views:

179

answers:

2

Is there a way to check a CASE when it's in an array:

SELECT CASE [Option] WHEN IN (1, 3, 99) THEN 'Wrong option' ELSE 'You go!' END
+4  A: 
SELECT CASE WHEN [Option] IN (1, 3, 99) THEN 'Wrong option' ELSE 'You go' END
jspcal
+2  A: 

You can use the CASE WHEN <predicate> THEN <value> ... END option, rather than the CASE <value> WHEN <value> THEN <value> ... END option.

SELECT CASE WHEN [Option] IN (1, 3, 99) THEN 'Wrong option' ELSE 'You go!' END

... but if the values are in a table, you could just do an outer join (and

CASE WHEN t.Value IS NULL THEN 'Not in list' ELSE 'In list' END

, or

CASE WHEN EXISTS (SELECT * FROM yourTable t WHERE t.value = [Option]) THEN 'Bad' ELSE 'Ok' END

...without a join.

Rob Farley