question

ssharma avatar image
ssharma asked

Can we use "Any" with a case statement?

can we use "Any in a case statement similiar to an "in"?
t-sqlany
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Usman Butt avatar image
Usman Butt answered
Yes you can. For e.g.
DECLARE @table TABLE
(
id INT
)

INSERT @table
        (
         [id]
        )
SELECT 1
UNION ALL SELECT 2
UNION ALL SELECT 3

SELECT *,
    CASE WHEN  [id] = ANY (SELECT 1 UNION ALL SELECT 2) THEN 1 ELSE 0 END IsAnyWorking 
FROM @table AS T
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.