繁体   English   中英

SQL Server:WHERE子句中的IF条件

[英]SQL Server : IF Condition in WHERE clause

我有一点参数

@IsInRetry

如果它是假的我必须设置where条件

attempts = 0

否则,如果它是真的我必须设置where条件

attempts > 0

怎么可以这样做?

试试这种方式:

( (@IsInRetry = 0 and attempts = 0) or (@IsInRetry = 1 and attempts > 0) )

尝试这个:

WHERE (attempts = @IsInRetry or (@IsInRetry = 1 and attempts > 0))

尝试这个,也应该为负面尝试工作:-)

@IsInRetry = (attempts > 0)

问候。

这个:

if @IsInRetry = 0x0
   BEGIN    
      SELECT * FROM dbo.tbl 
      WHERE attempts = 0
   END
ELSE    
   BEGIN 
      SELECT * FROM dbo.tbl 
      WHERE attempts = 1
   END

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM