I have an issue that has really stumped me in SQL Server.
I have recently had the need to insert a row in to a table, made up from a number of columns. I want to make the one row up from something like the below.
id | CustomerID | Key | Value
-------------------------
1 2 Firstname Tim
2 2 Secondname Skold
3 2 Age 48
4 2 Gender Male
So the output should be something like:
customerid | Firstname | Secondname | Age | Gender
-----------------------------------------------
2 Tim Skold 48 Male
I have tried to pivot the result, but can't get it to work, and have also tried to union the results, but this gives the results as a column, not as a single row.
The messy way in which this is being done currently is by joining on to the same table multiple times to get each field (firstname, secondname etc...)
Maybe unpivoting?
Really not sure, thanks for any help...
James.
EDIT***
Updated table view.