I have the following view in SQL Server 2008.
DEPT | EMP_ID | EMP_NAME | P_DATE | HOURS_WORKED
I want the view to be this way:
DEPT | EMP_ID | EMP_NAME | 2012-09-28 | 2012-09-29 | 2012-09-30 | 2012-10-01 ...
where the above date column header is P_DATE below which is "Hours_Worked" values of that employee on that particular date.
Like
2012-09-28
09:00:00
10:00:00
I am not sure whether I could achieve it using Pivot.
Please go to this link for clear understanding : SQL Server View Snapshots
You can perform this with the
PIVOT
function. If you know the values that you want to turn into columns than you can hard code then using a static pivot:See SQL Fiddle with Demo
If you have an unknown number of values, then you can use dynamic sql to
PIVOT
the data:See SQL Fiddle with Demo