I'm trying to get the correct order of operation in SQL for my case statement and every combination I try seems to be failing me.
When I run my simple statement of:
select CustomerName, AccountNumber, AccountID, VendorID, ClientID
from data
I yield results of:
CustomerName AccountNumber AccountID VendorID ClientID
Customer 1 3870465001 38
Customer 2 5135550000 48 58
Customer 3 8335 10 001 58 55 45
Here is what I'm currently trying:
select CustomerName, AccountNumber,
case
when AccountID = '' then VendorID
when AccountID = '' and VendorID = '' then ClientID
else AccountID
end as EffectiveID
from data
and hoping to see:
CustomerName AccountNumber EffectiveID
Customer 1 3870465001 38
Customer 2 5135550000 48
Customer 3 8335 10 001 58
but I only end with the result for Customer 2