如何在SQL Server存储过程中使用此查询?
@VAR1 VARCHAR(2),
AS
SELECT
*
FROM
TABLE1
WHERE
Colum1 = 1
CASE WHEN @VAR1 = 'OK' THEN
AND Colum2 = @Var1
ELSE
AND Colum2 IN ('String1','String2')
END
现在非常感谢你。
答案 0 :(得分:2)
正如Martin Smith在评论中已经指出的那样,你不能使用CASE
来换掉WHERE
条款。
你可以做的是:
SELECT
*
FROM
TABLE1
WHERE
Colum1 = 1
AND
(
(@VAR1 = 'OK' and Colum2 = @VAR1)
OR
(@VAR1 <> 'OK' and Colum2 IN ('String1','String2'))
)