Sometimes you want to test a given value against a list of values. Here you can use the special comparison operator IN to get it done. Below i have given two examples using IN operator..
Example 1:
DECLARE @my_id INT;
SET @my_id = 767;
SELECT CASE WHEN
@my_id IN (525, 272, 532, 767, 150, 637)
THEN 'I m Kavya.'
ELSE 'I m not Kavya.'
END;
GO
o/p: I m Kavya
Example 2:
DECLARE @my_id INT;
SET @my_id = 676;
SELECT CASE WHEN
@my_id NOT IN (525, 272, 532, 767, 150, 637)
THEN 'I m not Kavya.'
ELSE 'I m Kavya.'
END;
GO
o/p: I m not Kavya
How to use IN operator ?
Labels:
SQL Server
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment