我正在使用参数创建一个过程,并且基于参数我必须在where子句示例中放置不同的过滤器:
@para1
as
Select a,b,c from z
where @para1 = 0 then a = a
and @para1 = 1 then a between 1 to 10
and @para1 = 2 then a between 11 and 20
答案 0 :(得分:3)
使用LocationRequest.PRIORITY_HIGH_ACCURACY
逻辑
AND/OR
答案 1 :(得分:2)
你可以围绕这些线做点什么。以下AND
OR
的组合与CASE
Select a,b,c
from z
where (@para1 = 0 AND A = A ) -- A=A condition is pointless though
OR (@para1 = 1 AND a between 1 and 10 )
OR (@para1 = 2 AND a between 11 and 20)
答案 2 :(得分:1)
试试这个mehtod:
DECLARE @Cond AS NVARCHAR(1000)
if @para1 = 0
SET @Cond = ' a = a'
else if @para1 = 1
SET @Cond = ' a between 1 and 10'
else if @para1 = 2
SET @Cond = ' a between 11 and 20'
EXEC('Select a,b,c from z where ' + @Cond )
答案 3 :(得分:0)
你可以试试这个
if(@para1=0)
Begin
----
End
if(@para1=1)
Begin
----
End
如果你有多个条件,那么
select * from <tableName> where 1=1 AND (@para1=1 || ----)
AND (@para1=2 || ----)
答案 4 :(得分:0)
您好,您可以从参数测试开始,然后像这样的操作符。
@para1 as
Select a,b,c
from z
where (@para1 = 0) or (@para1 = 1 and a >= 1 and a <= 10) or (@para1 = 2 and a >= 11 and a <= 20);
注意a = a将始终返回true,除非a设置为null。
祝你好运。