Is there a way to use Wildcards with a LIKE compare statement in SQL

I have a stored procedure where I'm searching a table for Customers Name. SO for example

I have a parameter   @LastName

Is there a way to use the LIKE function with some sort of WildCard?

Such as Select LastName from Customer where LastName LIKE @LastName+'%'

I know that doesn't work but I'm trying to figure out the best way to use soem sort of wildcard so if the user is searching for a customer with lastname of JONES, they can just enter JON and see all the customers whose lastnames begin with JON.

I'm calling this sp from an aspx web page I can probable do the wild card through aspx but if I can just do it through the SP that would be better.

Thanks


svasilakosAsked:
Who is Participating?
 
Richard QuadlingSenior Software DeveloperCommented:
That should work fine.

I use that mechanism for many of my fuzzy reports.

The user enters the part of the name they know (say TONY) and they'll get ANTHONY, TONY.

Try this as a straight query (Using query analyzer or MS SQL Studio)...

DECLARE @LastName VARCHAR(MAX)
SELECT @LastName = 'JON'
SELECT LastName FROM Customer WHERE LastName LIKE '%' + @LastName + '%'

What do you get back?

0
 
svasilakosAuthor Commented:
I'm kind of an idiot. I didn't even try what I wrote in my question, I just thought I did and didn't think it would work.   That's the ticket...

Thanks for the Fast response.

-Steve, Las Vegas
0
 
Richard QuadlingSenior Software DeveloperCommented:
Glad to have helped.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.