0

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

1
  • Thanks Juan Carlos for editing it. Commented Jul 20, 2016 at 22:20

1 Answer 1

2
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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.