I have a table Customer with 2 columns Name and Surname (sql Server 2008). User wants to search by Name-Surname – or just typing Jo Bloggs. Suppose a row is filled with
CustomerId Name Surname
1 Jo Bloggs
doing
select * from customer where Name like '%Jo%' will find the records
select * from customer where Surname like '%Bloggs%' will find the records
But How can I make it return records for if user types both Name and Surname eg Jo Bloggs?
This should work whether user enters First Name, Surname or both.
I used two variables because entering input values into an SQL string is strongly discouraged, as it exposes to SQL Injection (other than being slower).