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