Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table and from which i have to create a report in a specified format.Here is the table fields from which we have to create the report.

UsernameUserIDCountyGroupnameProjectnameWorktypeDuration
ABC123CountyGroup 1Project 1Worktype 112
ABC123CountyGroup 2Project 2Worktype 318

In this table we can have N number of records enter but for time been i had given few sample data.Every CountygGroupName can have n number of Projects and every projects have few Worktypes defined under in it.

The Output report should be look like this:-


UserNameUserIDCountyGroup 1CountyGroup 2CountyGroup 3

Project1-----N Number of project under CountyGroup 1Project1-----N Number of project under CountyGroup 2Project1-----N Number of project under CountyGroup 3Total
Workytype 1----Worktype N under ProjectsWorkytype 1----Worktype N under ProjectsWorkytype 1----Worktype N under Projects
ABC123121830


Her we can see that in the first row we have all the distinct CountyGroupname Defined as columns and below those columns we have all the projects which lies under that county is created as columns and under each project the worktype under each project is defined as columns.

Please help me and guide me that how i approach to create such Dynamic Column for CountyGroupName and under it Project as per the CountyGroupName and finally Worktype as column under Project name and then i can fill the appropriate Duration Count as per the field.
Posted

1 solution

Use PIVOT - UNPIVOT

Using PIVOT and UNPIVOT[^]
Pivoting data in SQL Server[^](Alternate ways)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900