Possible silly question, but got me stumped. Compare 2 tables and return only distinct columns.
SELECT DISTINCT(DM.CLIENT_CODE) FROM DBO.DM_CLIENT DM
LEFT JOIN DBO.STG_DM_CLIENT STG
ON STG.CLIENT_CODE = DM.CLIENT_CODE
Aim of query is to return only new client_codes from DM table (or client_codes not listed in STG table).
I tought this would work, however does not.
can this query be then used in a case query to validate when new codes exists, then set resultset to ‘A’
select case
when (SELECT DBO.DM_CLIENT.Client_Code
FROM DBO.DM_CLIENT DM
LEFT JOIN DBO.STG_DM_CLIENT STG
ON STG.Client_Code= DM.Client_Code
WHERE STG.Client_Code IS NULL
GROUP BY DM.Client_Code) then 'A'
end
from DBO.DM_CLIENT.Client_Code, DBO.STG_DM_CLIENT.Client_Code
How can I make that statement to be a conditional statement?
Sounds like you want to return those from DM that don’t exist in STG.