我想构建一个包含以下逻辑的CASE语句,但是sql编译器不喜欢我的语句中的’OR’:
CASE expression WHEN expression1 OR expression2 THEN <yadda yadda> ELSE <yadda yadda> END
更具体的代码如下:
CASE @var1 WHEN '99' OR '22' THEN (CASE @var2 WHEN 'All' THEN col1 ELSE @var2 END) END@H_301_8@
解决方法
DECLARE @Variable INT; SET @Variable = 1; SELECT CASE WHEN @Variable = 1 OR @Variable = 2 THEN 'It is 1 or 2' WHEN @Variable = 3 THEN 'It is 3' ELSE 'It is not 1,2,or 3' END AS [SomeField]
MSDN docs for CASE,OR和Expressions.
@H_301_8@ @H_301_8@