sql server - SQL condition in join statement -
i have use conditional statement in join (sql server)
select * inner join b on a.id = b.id
if b.id null or b.id = ''
should a.id2 = b.id2
instead of a.id = b.id
is correct if this:
select * inner join b on (b.id not null , b.id <> '' , a.id = b.id) or ((b.id null or b.id = '') , a.id2 = b.id2)
i think not best way solve problem, useful, simple:
select * inner join b on a.id = b.id union select * inner join b on a.id2 = b.id2 b.id null or b.id = ''