SQL Server:WHERE子句中的IF条件
我有一个小参数SQL Server:WHERE子句中的IF条件,sql,sql-server,Sql,Sql Server,我有一个小参数 @IsInRetry 如果为false,我必须将where条件设置为 attempts = 0 否则,如果是真的,我必须将where条件设置为 attempts > 0 如何做到这一点?请尝试以下方法: ( (@IsInRetry = 0 and attempts = 0) or (@IsInRetry = 1 and attempts > 0) ) 这: 试试这个: WHERE (attempts = @IsInRetry or (@IsInRetry =
@IsInRetry
如果为false,我必须将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=(尝试次数>0)
问候。我需要在Where中指定条件,因为我有一个很长的查询,无法复制。
WHERE (attempts = @IsInRetry or (@IsInRetry = 1 and attempts > 0))