sql server - Case in SQL join statement -


i have use conditional statement in join:

select * inner join b on a.id = b.id 

if b.id null or b.id = '' or a.id null or a.id = '' should a.name = b.name, instead of a.id = b.id

i have use conditional statement in join:

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 not null , a.id <> '' , a.id = b.id) or     ((b.id null or b.id = '' or a.id null or a.id = '') , a.name = b.name) 

i think want this:

 select *  inner join bid on       (bid.id not null , bid.id <> '' , a.id not null , a.id <> '' , a.id = bid.id)  inner join bname on     ((bname.id null or bname.id = '' or a.id null or a.id = '') , a.name = bname.name) 

that join on b table twice, 1 join when id not null , second join when id null , join on name column instead. works case statement because 2 joins b table mutually exclusive.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -