How can I do a switched outer join with more than one table in SQL Server 2012? -
i have following select
select exam.name, test.type, test.testid, topic.name, exam.name test inner join exam on ( test.examid = exam.examid) inner join topic on ( test.topicid = topic.topicid) test.teststatusid = 1
when test.type = 1 there exam.name test when test.type = 2 there topic.name test
is there way can outer join , return name based on if type = 1 or 2 ?
use left join
, case
select test.type, test.testid, case when test.type = 1 exam.name when test.type = 2 topic.name end name test left join exam on test.examid = exam.examid left join topic on test.topicid = topic.topicid test.teststatusid = 1
Comments
Post a Comment