在条款中使用案例是否可行?
这样的事情
这样的事情
DECLARE @Status VARCHAR(50); SET @Status='published'; SELECT * FROM Product P WHERE P.Status IN (CASE WHEN @Status='published' THEN (1,3) WHEN @Status='standby' THEN (2,5,9,6) WHEN @Status='deleted' THEN (4,8,10) ELSE (1,3) END)
解决方法
不,你不能用这种情况.但你可以做
SELECT * FROM Product P WHERE @Status='published' and P.Status IN (1,3) or @Status='standby' and P.Status IN (2,6) or @Status='deleted' and P.Status IN (4,10) or P.Status IN (1,3)
BTW你可以减少到
SELECT * FROM Product P WHERE @Status='standby' and P.Status IN (2,3)
既然或P.Status IN(1,3)也给出了@ Status =’published’和P.Status IN(1,3)的所有记录