New to SQL and I’ve just created a SQL query with assitance:
SELECT CASE
WHEN exists (SELECT CLIENT_CODE FROM STG_DM_CLIENT
WHERE CLIENT_CODE
NOT IN (SELECT CLIENT_CODE FROM DM_CLIENT)) THEN 'A'
else
WHEN exists (SELECT STG.CLIENT_CODE AS TRAN_TYPE
FROM STG_DM_CLIENT STG
JOIN DM_CLIENT SRC
ON SRC.CLIENT_CODE = STG.CLIENT_CODE
WHERE (SRC.CLIENT_NAME <> STG.CLIENT_NAME)) THEN 'C'
END
FROM DM_CLIENT, STG_DM_CLIENT
Fails to provide the correct resulset, states incorect syntax next to when
Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword ‘WHEN’.
Any ideas as to what I’m doing wrong
It’s not clear what your after, this is the closest valid statement;
When the 1st exists is matched you will get A
When the 1st does not exist you will get C if the 2nd does match