gpt4 book ai didi

sql-server-2005 - 将比较运算符传递给 WHERE 子句

转载 作者:行者123 更新时间:2023-12-04 02:53:29 29 4
gpt4 key购买 nike

我想使用一个包含比较运算符的参数,例如 '=''>''>=' 并使用它在带有“case when then”的 where 子句中,或者像下面这样的 if 语句:

WHERE  
case @Operator
when '=' then (@Amount is null) or (@Amount = 0 ) or (Amount= @Amount)
when '>' then (@Amount is null) or (@Amount = 0 ) or (Amount> @Amount)
when '>=' then (@Amount is null) or (@Amount = 0 ) or (Amount>= @Amount)
END

最佳答案

我相信这会成功:

WHERE 
@Amount IS NULL
OR @Amount = 0
OR Amount = CASE @Operator WHEN '=' THEN @Amount END
OR Amount > CASE @Operator WHEN '>' THEN @Amount END
OR Amount >= CASE @Operator WHEN '>=' THEN @Amount END;

关于sql-server-2005 - 将比较运算符传递给 WHERE 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12553616/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com