where語句中多條件查詢欄位NULL與NOT NULL不確定性查詢

huyg發表於2014-07-18
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……

相關文章