SQL Server | Other
Additional SQL Server features and topics not covered by specific categories
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
It seems impossible to add a subquery in a CASE statement.
SELECT CASE WHEN Column1 IN (SELECT Column2 FROM Table2)
THEN 'Y'ELSE 'N' END
FROM Table1
Any suggestions?
Additional SQL Server features and topics not covered by specific categories
Answer accepted by question author
Hi @Y.N Try this:
SELECT CASE WHEN EXISTS (SELECT 1 FROM Table2 B WHERE B.Column2 = A.Column1)
THEN 'Y' ELSE 'N' END
FROM Table1 A
Best regards,
Cosmog Hong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.