根据用户定义的变量选择Statement

时间:2013-05-09 15:16:43

标签: sql sql-server reporting-services case

我试图根据用户的输入(SSRS)做一个简单的select语句。救命!

select * from Table1
WHERE
Case when @x = 'Yes' then (select * from Table1 where [Column1] < 0) end; 
case when @x = 'No' then (select * from Table1 where [Column1] > 0) end;

提前谢谢

KJ

1 个答案:

答案 0 :(得分:3)

应该像

一样简单
select * from Table1
WHERE
(@x = 'Yes' AND [Column1] < 0)
OR
(@x = 'No' AND [Column1] > 0);

顺便说一句,SELECT *编码非常糟糕,你真的应该指定你要返回的每一列。