对于每天在 sql 上工作的人来说,这听起来很容易,这些人占用了我很多时间。我有一个表,如果值为空,则我需要根据变量值选择记录,将状态列设置为不等于 3,变量值不等于基于变量值的空过滤器..
DECLARE @status int
set @status = 1
SELECT change_set_history_id, files_changed, is_previewed
FROM dbo.ChangeSetHistory WITH (NOLOCK)
WHERE [user_name] = 'djacob' AND
[culture] = 'nl-NL' AND
(@status IS NULL AND [status] <> 3) OR (@status IS NOT NULL AND [status] = @status) AND
[approver] = null AND
is_deleted = 0
如果它尝试使用这部分查询它可以工作 DECLARE @status int set @status = 1 select * from ChangeSetHistory where status = @status and user_name = 'djacob' andculture = 'nl-NL'