首页 > 代码库 > where语句中多条件查询字段NULL与NOT NULL不确定性查询

where语句中多条件查询字段NULL与NOT NULL不确定性查询

SELECT * FROM Tablewhere a.TenantKey=@TenantId AND (@ProjectKeys is null or b.RecuritProjectKey in (select * from dbo.f_SplitToInt(@ProjectKeys,,)))AND (@ProjectDutyUserKeys is null or b.ProjectDutyUserKey in (select * from dbo.f_SplitToInt(@ProjectDutyUserKeys,,)))

当@ProjectKeys&@ProjectDutyUserKeys两个参数有值无值都不会影响查询,省去了IF……ELSE……