Problems using like for a title search

Discussion in 'ASP General' started by Bill, Sep 5, 2003.

  1. Bill

    Bill Guest

    I'm trying to pull up all the titles in our database that have a word
    like the one submitted from our search form.

    The string is like this:


    title=request.form("title")

    sql=" SELECT * FROM books where title like '"&%title%&"' ORDER BY
    title "

    If I run a search straight in sql server using the %title% with the
    percent signs before and after the variable name title, it will
    dutiflly return all the titles that contain that word. However, when I
    run the above string in asp, I get an error. Note I have '"&%title%&"'
    That's quite a lot wrapped around it. I've tried a few variations of
    this, but keep getting error messages. How do I do an approximate
    search this way?

    Thanks,

    Bill
     
    Bill, Sep 5, 2003
    #1
    1. Advertising

  2. Try this:

    sql=" SELECT * FROM books where title like '%"& title "%' ORDER BY title "



    --
    Manohar Kamath
    Editor, .netBooks
    www.dotnetbooks.com


    "Bill" <> wrote in message
    news:...
    > I'm trying to pull up all the titles in our database that have a word
    > like the one submitted from our search form.
    >
    > The string is like this:
    >
    >
    > title=request.form("title")
    >
    > sql=" SELECT * FROM books where title like '"&%title%&"' ORDER BY
    > title "
    >
    > If I run a search straight in sql server using the %title% with the
    > percent signs before and after the variable name title, it will
    > dutiflly return all the titles that contain that word. However, when I
    > run the above string in asp, I get an error. Note I have '"&%title%&"'
    > That's quite a lot wrapped around it. I've tried a few variations of
    > this, but keep getting error messages. How do I do an approximate
    > search this way?
    >
    > Thanks,
    >
    > Bill
     
    Manohar Kamath [MVP], Sep 5, 2003
    #2
    1. Advertising

  3. Bill

    dlbjr Guest

    strSQL = " SELECT * FROM books WHERE title LIKE %" & title & "% ORDER BY
    title "

    dlbjr

    Unambit from meager knowledge of inane others,
    engender uncharted sagacity.
     
    dlbjr, Sep 5, 2003
    #3
  4. Bill

    Bill Guest

    Thanks! That worked great.

    Bill

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Bill, Sep 5, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    1
    Views:
    465
    Steve C. Orr, MCSD
    Aug 10, 2003
  2. Replies:
    0
    Views:
    538
  3. Replies:
    1
    Views:
    553
    David
    Apr 24, 2007
  4. soonic
    Replies:
    11
    Views:
    1,783
    soonic
    Jul 27, 2011
  5. Russell
    Replies:
    2
    Views:
    289
    Russell
    Sep 13, 2004
Loading...

Share This Page