Let’s say I have a simple select query that returns the following:
ID Name1 Name2 Description1 Description2 Notes1 Notes2
1 A B AA BB AAA BBB
2 C D CC DD CCC DDD
and I want to return dataset as follows:
ID ColumnName 1st 2nd
1 Name A B
1 Description AA BB
1 Notes AAA BBB
2 Name C D
2 Description CC CC
2 Notes DDD DDD
Any way of doing that in sql server 2008-r2?
Looks like it’s a job for PIVOT but a’m confused on how to achieve this with PIVOT
You can use this, assuming the values are static or not so numerous that patching it up with your actual values isn’t too painful:
Yet another great example of why data normalization is so important.