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

SELECT * FROM Table
where 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……

posted on 2014-07-18 15:49  huyg  阅读(1009)  评论(0编辑  收藏  举报