like statement in SQL query in Access

Discussion in 'ASP General' started by ITHELP, Jul 21, 2005.

  1. ITHELP

    ITHELP Guest

    I am using a form to find some data from a table. In the table are
    fields such as Client name, job number, and job description. I built a
    query using a SQL statement through the 'Record source' for the form. I
    can get the query to work if I type in the Client name exactly as it is
    in the table. However, I want to be able to use a like statement to
    expand my search and find all records with a certain word or year in
    it. How can I get this to work?
    Currently the SQL statement looks like: SELECT [CD Query].* FROM [CD
    Query] WHERE ((([CD Query].[PROJECT NUMBER])=Forms!CDtest!scanned));
    CD Query is the name of the Query, I'm searching by project number,
    CDtest is the name of the form, and scanned is the name of the text box
    where I enter what I'm looking for.
    Any help is greatly appreciated. Thanks!
     
    ITHELP, Jul 21, 2005
    #1
    1. Advertising

  2. I assume you submit the form, and aren't trying to do this as the user is on
    the page.

    sql = "SELECT * FROM [CD Query] WHERE [Project Number] LIKE '%" &
    replace(request.form("scanned"), "'", "''") & "%'"

    You really should consider better object names. Why the spaces? Do you
    like typing square brackets all over the place? And try to avoid SELECT *
    in production code.

    Also, you might find this page useful:
    http://www.aspfaq.com/2183





    "ITHELP" <> wrote in message
    news:...
    >I am using a form to find some data from a table. In the table are
    > fields such as Client name, job number, and job description. I built a
    > query using a SQL statement through the 'Record source' for the form. I
    > can get the query to work if I type in the Client name exactly as it is
    > in the table. However, I want to be able to use a like statement to
    > expand my search and find all records with a certain word or year in
    > it. How can I get this to work?
    > Currently the SQL statement looks like: SELECT [CD Query].* FROM [CD
    > Query] WHERE ((([CD Query].[PROJECT NUMBER])=Forms!CDtest!scanned));
    > CD Query is the name of the Query, I'm searching by project number,
    > CDtest is the name of the form, and scanned is the name of the text box
    > where I enter what I'm looking for.
    > Any help is greatly appreciated. Thanks!
    >
     
    Aaron Bertrand [SQL Server MVP], Jul 21, 2005
    #2
    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. Anonymous
    Replies:
    0
    Views:
    1,545
    Anonymous
    Oct 13, 2005
  2. Toni

    SQL: Specific LIKE statement

    Toni, Oct 16, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    301
    bruce barker
    Oct 16, 2008
  3. Rob
    Replies:
    2
    Views:
    242
    Eran Amitai
    Jan 27, 2004
  4. Guy Hocking

    ASP / SQL Query - Conditional SELECT Statement

    Guy Hocking, Jan 21, 2004, in forum: ASP General
    Replies:
    7
    Views:
    213
    Bob Barrows
    Jan 21, 2004
  5. Roland Hall

    ASP LIKE query using parameterized query

    Roland Hall, Jan 12, 2007, in forum: ASP General
    Replies:
    8
    Views:
    232
    Roland Hall
    Jan 13, 2007
Loading...

Share This Page