Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a query
SQL
Select Employee_Name, TaskTitle, Hours, TaskDate From TimeSheet TS, employee E, Timesheetdetails TSD, Task T where
TS.EmployeeID = E.Employee_EmpID AND
TSD.TaskID = T.TaskID AND
TS.TImeSheetID = TSD.TimeSheetID


which results in
EmployeeName   TaskTiitle   Hours
A                Task1           0
A                Task2           3
B                Task1           4


I want the result like

	A	B	C		
Task 1	3(Hours)	1			
Task 2	2	5	1		
Task 3	4	2	6	

….
Posted
Updated 28-Sep-11 0:01am
v2

1 solution

This is called a pivot, if you are using MSSQL 2005 or greater look at the following link : Using PIVOT and UNPIVOT

More examples : SQL SERVER - PIVOT and UNPIVOT Table Examples
 
Share this answer
 
v2
Comments
Pravin Patil, Mumbai 28-Sep-11 6:05am    
Nice links..
My 5
Mehdi Gholam 28-Sep-11 6:10am    
Cheers
Inderjeet Kaur 28-Sep-11 8:04am    
I have 50 employees how will i bring them to header and assign their hours to them downunder

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