October 31, 2006 at 2:30 pm
I have a data model where the voter answers can come from 2 different tables.
So when I try to query the voter responses, I have results that look as below:
Voter ID QuestionText Tab1.AnswerText Tab2.AnswerText
________________________________________________________
2 Question1 null Yes
2 QUestion2 null US Central
2 Question 3 This is some answer!!
I would like to get an output as below:
Voter ID QuestionText AnswerText
___________________________________________
2 Question1 Yes
2 QUestion2 US Central
2 Question 3 This is some answer!!
Is it possible with T-SQL (sql server 2000)? Thanks
October 31, 2006 at 2:46 pm
select voterid, questiontest,
case when tab1.answertext is not null then tab1.answertext when tab2.answertext is not null then tab2.answertext end as answertext
from yada
October 31, 2006 at 2:47 pm
Something Like
select VoterId, a.QuestionText, coalesce(A.AnswerText, b.AnswerText) as AnswerText
from Tab1 a
join Tab2 b on a.QuestionText = b.QuestionText
and a.VoterID = b.VoterID
October 31, 2006 at 3:13 pm
Thank you both, Yada and Ray. Works wonderfully.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply