Ok I have a table that looks like this
ItemID | ColumnName | Value
1 | name | Peter
1 | phone | 12345678
1 | email | peter@host.com
2 | name | John
2 | phone | 87654321
2 | email | john@host.com
3 | name | Sarah
3 | phone | 55667788
3 | email | sarah@host.com
Now I need to turn that into this:
ItemID | name | phone | email
1 | Peter | 12345678 | peter@host.com
2 | John | 87654321 | john@host.com
3 | Sarah | 55667788 | sarah@host.com
I have been looking at dynamic pivot examples, but it seems Im not able to fit them into my scenario.
Can anyone help?
Have a look at the following example
You don't need dynamic pivot, becuase it will be a different table. Simply do something like this:
Check this SQL fiddle
Have you tried this:
try this:
SQL Server 2005+
SQL Fiddle Demo
Here's a query I'm using for my contactlist :)