Reputation: 17
I have a table in sql server 2005 where there are 3 columns id ,question and answer.
the data is as below-
id question answer
1 married yes
1 name John
2 married No
2 name Dave
3 married yes
3 name Rob
I'm expecting results like the one below-
ID married name
1 yes John
2 no Dave
3 yes Rob
Thanks in advance
Upvotes: 0
Views: 31
Reputation: 69574
Select ID
,MAX(CASE WHEN question = 'married' THEN answer END) AS Married
,MAX(CASE WHEN question = 'name' THEN answer END) AS Name
FROM TableName
GROUP BY ID
Upvotes: 2