SELECT DISTINCT Security.Users.UserID, Security.Users.KnownAs, Security.Users.Email, Security.Users.NTAccount FROM Security.Users INNER JOIN Security.UserRoles ON Security.UserRoles.UserID = Security.Users.UserID LEFT JOIN Wf.WorkflowTemplateParticipantRoles ON Wf.WorkflowTemplateParticipantRoles.RoleID = Security.UserRoles.RoleID WHERE (CASE WHEN ISNULL(@SearchText, '') <> '' THEN CASE WHEN KnownAs LIKE '%' + @SearchText + '%' THEN 1 ELSE 0 END ELSE 1 END ) = 1 AND (CASE WHEN ISNULL(@UserID,'') <> '' THEN CASE WHEN Security.Users.UserID = @UserID THEN 1 ELSE 0 END ELSE 1 END ) = 1 AND (CASE WHEN ISNULL(@FirstName, '') <> '' THEN CASE WHEN FirstName LIKE '%' + @FirstName + '%' THEN 1 ELSE 0 END ELSE 1 END ) = 1 AND (CASE WHEN ISNULL(@LastName, '') <> '' THEN CASE WHEN LastName LIKE '%' + @LastName + '%' THEN 1 ELSE 0 END ELSE 1 END ) = 1 AND (CASE WHEN ISNULL(@RoleIDs, '') <> '' THEN CASE WHEN Wf.WorkflowTemplateParticipantRoles.RoleID IN(SELECT Value FROM System.Fn_GenSplitCSV(@RoleIDs,',')) THEN 1 ELSE 0 END ELSE 1 END ) = 1 ORDER BY KnownAs ASC 