Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 23, 2013 02:06 AM by Chen Yu - MSFT
Jan 16, 2013 10:53 AM|LINK
Consider i have 3 tables, tableA, tableB and tableC. I want to join tableA with tableB if tableA.flg=1 else with tableC
Jan 16, 2013 11:13 AM|LINK
Try something like this:
from TableA as a
left join TableB as b
on a.Flg = 1 and b.IdA = a.IdA
left join TableC as c
on a.Flg <> 1 and c.IdA = a.IdA
Hope this help.
Jan 23, 2013 02:06 AM|LINK
You could also try to use case when in the select clause to choose one output column from Table A or Table B like below.
select column1 = case when tableA.flg = 1 then tableA.id else tableB.id end, column2 ....
left join TableB on ....
left join TableC on ....