SQL CASE [Column] WHEN IN('case1','case2')那么'oops'END?

时间:2022-04-24 07:53:35

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

有没有办法在数组中检查CASE:

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

2 个解决方案

#1


20  

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

#2


4  

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

您可以使用CASE WHEN <谓词> THEN <值> ... END选项,而不是CASE <值> WHEN <值> THEN <值> ... END选项。

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.

......没有加入。

#1


20  

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

#2


4  

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

您可以使用CASE WHEN <谓词> THEN <值> ... END选项,而不是CASE <值> WHEN <值> THEN <值> ... END选项。

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.

......没有加入。