all groups > sql server programming > september 2007 >
You're in the

sql server programming

group:

Adding a wildcard to a stored proc parameter



Adding a wildcard to a stored proc parameter shmeian
9/30/2007 6:18:00 PM
sql server programming: Hi there,

I have a simple problem but I can't solve it.
I'm using the CONTAINS predicate to find names in a column called LAST_NAME.
eg:
SELECT bladebla FROM table bla
WHERE CONTAINS( [LAST_NAME], @nameparam)

But what I really want to do is something like this:
WHERE CONTAINS( [LAST_NAME], @nameparam + '*')
where * is a wildcard so if 'S' is passed into my proc it'll return Smith,
Simpson, Slick etc.

I can't find an example with the correct syntax for concatenating a wildcard
onto a parameter. Simple you'd think but how do I do this?

Many thanks,
Ian.

Re: Adding a wildcard to a stored proc parameter Kalen Delaney
9/30/2007 6:26:33 PM
Hi Ian

The wildcard character for SQL Server strings is '%' and you can look for a
string using a wildcard using the LIKE operator. Make sure your parameter is
defined as varchar instead of fixed length char, and then it would look
something like this:

SELECT bladebla FROM table bla
WHERE LAST_NAME LIKE @nameparam + '%'

---
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com


[quoted text, click to view]

Re: Adding a wildcard to a stored proc parameter shmeian
9/30/2007 7:02:10 PM
Thanks Kalen. That did the trick.

[quoted text, click to view]
AddThis Social Bookmark Button