I tried following several other suggestions on this website but coulnd't make this work for some reason.
Basically I'm trying to get from this table of Tasks:
| TaskID | ProjectID | TaskType | TaskDate1 | TaskDate2 |
---------------------------------------------------------
| 1 | 1 | Type4 | 20130401 | 20130506 |
| 2 | 1 | Type0 | 20130412 | 20130508 |
| 3 | 1 | Type2 | 20130420 | 20130517 |
To that one:
| ProjectID | Type0Date1 | Type0Date2 | Type2Date1 | Type2Date2 | Type4Date1 | Type4Date2 |
---------------------------------------------------------
| 1 | 20130412 | 20130508 | 20130420 | 20130517 | 20130401 | 20130506 |
Each project has to have each of several predefined tasks (identified by their type). These tasks have a lot of properties but I'm interested in 2 dates and it would be nice to bring them all in one row per project.
I can easily pivot it for one of the columns with: PIVOT (MAX(TaskDate1) FOR TaskType IN ([Type0],[Type2],[Type4]))
I tried duplicating the TaskType column and doing another pivot around it for TaskDate2 but that won't give me a single row.
I also can't wrap my head around how unpivoting the table first would get me where I need to be, as was the suggestion in some other posts for similar questions.
If there is a scalable way of doing this (as in pivoting even more columns) it would be nice to know.
Thanks.