multiple like params in where clause
i have a table with a varchar(500) product description field.
a user can search on the product description by entering numerous keywords.
i'm trying to write a stored proc (don't want to have to use dynamic sql)
to select all products that have words product descriptions that match the keywords
in a normal, single parameter proc i would use something like
Code:
where productdescription like '%' + @blah + '%'
but with a variable number of possible parameters i can't do something like this inside a proc
Code:
where productdescription like '%blah%'
or productdescription like '%stuff%'
--etc etc etc
so how do i handling the fact thet i need to be able to do like comparisons for a variable number of arguments?
Re: multiple like params in where clause
What do you mean by "i can't do something like this..." ... why not?
Code:
WHERE
ProductDescription LIKE ('%' + @Parm1 + '%')
Or
ProductDescription LIKE ('%' + @Parm2 + '%')
Should work just fine.... what doesn't work?
-tg
Re: multiple like params in where clause
because what if there are 5 keywords to search on, or 10?
remember i don't want to use dynamic sql i want a proc that returns the results.
after a couple of hours googling i've found the following articles
http://www.sqlteam.com/article/keywo...sequence-table
http://www.sqlteam.com/article/searching-on-sqlteamcom
that seem to do what i want
Re: multiple like params in where clause
OK... one sec now.... how are you passing them in? As a single line, separated by a delimiter? Or as actual separate parameters? If you are passing it in as a single delimited string, then that second link would probably be the better choice.
-tg
Re: multiple like params in where clause
I haven't actually read the link but I'd agree - Pass in a comma separated field, parse it out and treat it as a rowset that you can deal with.