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    INNER JOIN Md.OfficeLocationSetup    ON Md.OfficeLocationSetup.OfficeLocationID = Security.Users.OfficeLocationID  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(@RoleIDs, '') <> '' THEN                     CASE                         WHEN Security.UserRoles.RoleID IN                              (                                  SELECT Value FROM System.Fn_GenSplitCSV(@RoleIDs, ',')                              ) THEN                             1                         ELSE                             0                     END                 ELSE                     1             END            ) = 1      ORDER BY KnownAs ASC;