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……