Here is my test T-SQL.
DECLARE @TestVal INT
SET @TestVal = 1
SELECT
CASE @TestVal
WHEN (1 | 2 | 6) THEN 'First' // I would like to check 1 or 2 or 6.
WHEN 3 THEN 'Second'
WHEN 4 THEN 'Third'
ELSE 'Other'
END
The current result is 'Other'.
I would like to get the result as 'First'. How can I use (OR statement) in my T-SQL.
Best regards
Use the condition form of case:
SELECT (CASE WHEN @TestVal IN (1, 2, 6) THEN 'First'
WHEN @TestVal = 3 THEN 'Second'
WHEN @TestVal = 4 THEN 'Third'
ELSE 'Other'
END)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With