SELECT DISTINCT DotMemberID, (CASE WHEN IDNumber IS NULL THEN RegistrationNumber ELSE IDNumber END) AS IDNumber, SysMemberTypeID, SysIDTypeID, FirstName, LastName, PostalAddress, PostalAddressCode, PhysicalAddress, PhysicalAddressCode, TradeName, TelNumber, FaxNumber, CellNumber, EmailAddress, TaxNumber FROM dbo.DotMembers WHERE Cancelled = 0 AND(CASE WHEN @FirstName IS NULL THEN 1 ELSE CASE WHEN FirstName LIKE '%' + @FirstName + '%' THEN 1 ELSE 0 END END) = 1 AND (CASE WHEN @LastName IS NULL THEN 1 ELSE CASE WHEN LastName LIKE '%' + @LastName + '%' THEN 1 ELSE 0 END END) = 1 AND (CASE WHEN @IDNumber IS NULL THEN 1 ELSE CASE WHEN IDNumber LIKE '%' + @IDNumber + '%' OR RegistrationNumber LIKE '%' + @IDNumber + '%' THEN 1 ELSE 0 END END) = 1 ORDER BY FirstName ASC