This should work whether the user will enter a first name, last name, or both.
SELECT *
FROM customer cus
WHERE ((cus.Name like @FirstName) OR (@FirstName IS NULL)) AND
((cus.Surname like @Surname) OR (@Surname IS NULL))
I used two variables because inputting input values into an SQL string is very discouraged since it provides SQL Injection (except slow).
Diego source
share