vb.net and crystal report - vb.net

I have a list of employee on a list view. In every employee there are list of task on each employee. I want to print in in crystal report per employee and their respective tasks. Once print button was click then I have a query to get all employees and loop to get their respective tasks. My problem now is the crystal report displaying. Please take a look sample result below I want to achieve. Thanks in advance.
Juan De La Cruz
Task | No of hours | Date
task 1 | 59 | 2014/01/05
task 2 | 60 | 2014/01/06
Justin Garcia
Task | No of hours | Date
task 1 | 35 | 2014/01/05
task 2 | 23 | 2014/01/06

In the report itself from (Field Explorer) select Group Name Fields, Select Group Expert and Select under Group By the groping criteria which in your case (Employee Id OR Employee Name) as your requirement so the report will show each employee information in separated section as you need in the question.

Related

Auto generate columns in Microsoft Access table

How can we auto generate column/fields in microsoft access table ?
Scenario......
I have a table with personal details of my employee (EmployDetails)
I wants to put their everyday attendance in an another table.
Rather using separate records for everyday, I want to use a single record for an employ..
Eg : I wants to create a table with fields like below
EmployID, 01Jan2020, 02Jan2020, 03Jan2020,.........25May2020 and so on.......
It means everyday I have to generate a column automatically...
Can anybody help me ?
Generally you would define columns manually (whether that is through a UI or SQL).
With the information given I think the proper solution is to have two tables.
You have your "EmployDetails" which you would put their general info (name, contact information etc), and the key which would be the employee ID (unique, can be autogenerated or manual, just needs to be unique)
You would have a second table with a foreign key to the empployee ID in "EmployDetails" with a column called Date, and another called details (or whatever you are trying to capture in your date column idea).
Then you simply add rows for each day. Then you do a join query between the tables to look up all the "days" for an employee. This is called normalisation and how relational databases (such as Access) are designed to be used.
Employee Table:
EmpID | NAME | CONTACT
----------------------
1 | Jim | 222-2222
2 | Jan | 555-5555
Detail table:
DetailID | EmpID (foreign key) | Date | Hours_worked | Notes
-------------------------------------------------------------
10231 | 1 | 01Jan2020| 5 | Lazy Jim took off early
10233 | 2 | 02Jan2020| 8 | Jan is a hard worker
10240 | 1 | 02Jan2020| 7.5 | Finally he stays a full day
To find what Jim worked you do a join:
SELECT Employee.EmpID, Employee.Name, Details.Date, Details.Hours_worked, Details.Notes
FROM Employee
JOIN Details ON Employee.EmpID=Details.EmpID;
Of course this will give you a normalised result (which is generally what's wanted so you can iterate over it):
EmpID | NAME | Date | Hours_worked | Notes
-----------------------------------------------
1 | Jim | 01Jan2020 | 5 | ......
1 | Jim | 02Jan2020 | 7 | .......
If you want the results denormalised you'll have to look into pivot tables.
See more on creating foreign keys

Result of a Query in One Column on Another Query

I need to create a report that shows attendance at a weekly class. We use an electronic check-in system so each person's info is saved with a date into the database.
I can easily write a query that gets the list of people who checked in to the class on a given day. The results from that query look something like this:
+-----------+------------+-----------+
| person id | first name | last name |
+-----------+------------+-----------+
| 1234 | john | smith |
| 1235 | jane | smith |
+-----------+------------+-----------+
But what I need is an additional column that says how many times the particular person has attended that class within a 12 week period. So the results I want would look something like this:
+-----------+------------+-----------+------------+
| person id | first name | last name | attendance |
+-----------+------------+-----------+------------+
| 1234 | john | smith | 3 |
| 1235 | jane | smith | 5 |
+-----------+------------+-----------+------------+
I can also get the proper results for the "attendance" column with a COUNT query. This query only works when I specify a person ID in the attendance table.
So I need a query that will take the person ids from the first query and figure out how many times that person has attended in the last 12 weeks and apply that to a column.
Additional information:
It needs to count how many times the person has attended that class in a 12 week period including the last Sunday.
It is always 12 weeks from the current date
I suppose it is possible they could have attended two classes in a day but all the classes are on a Sunday and it is unlikely enough that I do not need to account for this
It is all based on a Sunday so I guess the answer is 12 weeks from last Sunday.
Here's my query that returns the results of who checked in last Sunday:
SELECT
pb.person_id, pb.nick_name, pb.last_name, COS.occurrence_name, COS.occurrence_description, COS.date_created, COS.occurrence_type, COS.occurrence_id, sm.role_luid
FROM core_v_occurrence_service COS
JOIN core_occurrence_attendance oa ON oa.occurrence_id = COS.occurrence_id
JOIN core_v_person_basic pb ON pb.person_id = oa.person_id
JOIN smgp_member sm ON sm.person_id = OA.person_id
WHERE oa.attended = 1
AND COS.occurrence_type = 140
AND COS.date_created BETWEEN (DATEADD(week,-1,GETDATE())) AND GETDATE()
AND sm.role_luid IN (24,25, 28)
AND sm.group_id = 3
And here's the query that gives me the count of how many times someone has attended a class:
SELECT COUNT (oa.person_id)
FROM core_occurrence_attendance oa
JOIN core_v_occurrence_service COS on cos.occurrence_id = oa.occurrence_id
WHERE oa.person_id = 27276
AND oa.attended = 1
AND COS.occurrence_type = 140
AND COS.date_created BETWEEN (DATEADD(week,-12,GETDATE())) AND GETDATE()
Basically what I need is a query that count how many times a person's person id is entered into the attendance table. Because a person's person id will be entered into that table every time they attend the class.
You should be able to add a group by into the query:
SELECT Person_ID, FIRST_NAME, LAST_NAME, COUNT(Person_ID) AS Attendance
FROM <YOURTABLE>
WHERE <DateField> BETWEEN <begindate> AND <enddate>
GROUP BY Attendance
The group by will count how many times that person has shown up for class and put it into one cell.
I a not guaranteeing this code runs because you post is missing some information.replace everything in the angle brackets.
I did it!
I created a CTE for the query that counts the attendance.
I then did SELECT DISTINCT on that CTE and added a GROUP BY with all the column names.
I also added the date range of 12 weeks I needed in the CTE.

Microsoft SQL report builder: Multiple row 'duplicates' to one row per ID

Microsoft SQL Server report Builder
I have a query which returns a variety of information from our Community Intelligence database which runs something like this:
SELECT
viewadhocorganisation.[org_id]
..../other fields
viewadhocorganisationmainactivities.[Main Activity]
FROM
viewadhocorganisation LEFT JOIN viewadhocorganisationmainactivities
ON viewadhocorganisation.[OrganisationID] = viewadhocorganisationmainactivities.[Organisation ID]
WHERE
viewadhocorganisation.[city name] = 'MyCity'
This returns each organisation with its respective fields on a new row with each of its main activities listed seperately in a new row (i.e duplicating)
hence SELECT DISTINCT does nothing in this instance as each row is not strictly a duplicate
ie return is :
ID | Org Name | other fields | Main Activity
1 | Org 1 | other fields | Activity 1
1 | Org 1 | other fields | Activity 2
1 | Org 1 | other fields | Activity 3
1 | Org 1 | other fields | Activity 4
2 | Org 2 | other fields | Activity 1
2 | Org 2 | other fields | Activity 5
2 | Org 2 | other fields | Activity 7
2 | Org 2 | other fields | Activity 8
Main Activity is a text string populated from a seperate Lookup Table (maintained by a central sysadmin) I have tried various SUM, AGGREGATE, (also tried various JOIN, LOOKUP SET but I seem to be running into a lot of errors though I may be using it incorrectly) but have yet to find a solution to get the desired output where all main activities are in one row seperated by a comma :
Output required:
Org_ID | Org Name | other fields | Main Activity
1 | Org 1 | other fields | Activity 1, Activity 2, Activity 3
2 | Org 2 | other fields | Activity 1, Activity 5, Activity 7
The intention is to get a dump of information to integrated into google maps API showing address of Org 1, org 2 etc showing their main activities which I have a procedure for already but am unable to collate the Main activity field into one row
Edit: I have no access to the back end and can only report from the views and tables created by our vendor
you can use temporary tables to achieve this.
make your desired string of activities in one temporary from viewadhocorganisationmainactivities then join that temp table with your main table i.e viewadhocorganisation.
You need to join the table with itself and use the stuff clause to get the strings in a comma separated format. See this fiddle

Grouping issue in SSRS

So I have a table that has divisions and sub-divisions. The structure is as follows:
COMPANYID | DIVISIONID | DIVISION | PARENTID
1 | 1 | North | NULL
1 | 2 | South | NULL
1 | 3 | East | NULL
1 | 4 | West | NULL
1 | 5 | Sales | 1
1 | 6 | Service | 1
1 | 7 | Sales | 2
1 | 8 | Service | 2
1 | 9 | Sales | 3
1 | 10 | Service | 3
1 | 11 | Sales | 4
1 | 12 | Service | 4
The idea behind the table is that the data would indicate all of those divisions/subdivisions are the for the same company. Anything with a null PARENTID is a "Division" and anything that has a PARENTID is a "Sub-Division". There will be a max of 2 tiers (Division --> Subdivision). This table would create the following hierarchy:
Company 1
North
Sales
Service
South
Sales
Service
East
Sales
Service
West
Sales
Service
I am trying to make an SSRS report that shows details about the company including a table with all the divisions and sub-divisions. I am using the following query to retrieve a list of all the divisions and subdivisions:
SELECT division, parentid
FROM division
WHERE companyid=#companyid
#companyid is a parameter for the report. My thought process is that I want create a table that has a Parent group and a Detail group where the Parent group would be all those rows that have a null PARENTID and then the Detail group would list all rows whose PARENTID equals the divisionid of Parent row. I'm just not sure how to set that up in the groups. Filters? Separate queries? Do it in the SQL query?
Any and all help is greatly appreciated! Thanks!
For a simple hierarchy with a maximum of 2 levels you can just join the table on itself:
SELECT D1.CompanyId, D1.DivisionId, D1.Division, D2.Division AS Subdivision
FROM DivisionTable D1
INNER JOIN DivisionTable D2 ON D1.DivisionId = D2.ParentId AND D1.CompanyId = D2.CompanyId
WHERE D1.CompanyId = #CompanyId
If i understood your goal correctly, you want the report to display the information in hierarchy mode.
If so you can achieve it with setting a Recursive Hierarchy Group.
Reporting services has the ability to display "hierarchy" information in a "tree" layout
For more information look here
You don't have to create another query the first one that has the CompanyID And the ParentID is just fine
You just need your select statement as a dataset and SSRS can do the grouping for you. You can even tier on multiple levels or better yet collapse and expand your groupings based on filters.
How to get started:
Create your dataset as you have shown
Put in a table object from the toolbox
Only put in the columns of detail data
In the lower left of the 'Design' layout click the 'detail's and click 'add Group>Parent Group'. Select your grouping
If you want you can 'collapse' on demand the details columns. You can choose 'Visibility' on the detail grouping. 'When the report is initially run'>Choose 'Hide'. Check 'Display can be toggled by this report item': Select a cell reference to what you want to expand the details with.

SSRS report table including Averages

I need a report that has some data in it with calculation data among regular rows. For example:
Name | Age | Salary
HR | 35 | $1300
John | 30 | $1000
Mark | 40 | $1600
Law | 45 | $1500
Bill | 40 | $1000
Sara | 50 | $2000
The idea is to group rows by a field and then add a row with average numbers for this group.
Is it possible? I also have 2 date parameters (start and end), so I need to get all the records to SSRS and then filter them out...
Yes, this is possible and very straight forward.
Create your report with the data rows, then create a group on the Department field. You can do this a few ways: right click on the detail rows and select Add Group... or drag the department field to the Row groups pane in the design window.
Add a row to the group by right clicking on the details group and choosing to add a total, before the details. In the new row, set your formula to be =Avg(MyDataset!AgeFieldName.Value)
Take a look at the tutorials available on MSDN, especially the Grouping and Totals section