Results 1 to 5 of 5

Thread: multiple like params in where clause

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    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?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    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

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width