Syntax Error on SQL statement

Discussion in 'ASP General' started by dthmtlgod, Oct 8, 2004.

  1. dthmtlgod

    dthmtlgod Guest

    I am getting a syntax error on my SQL statement, not sure if I am doing this
    right. i am trying to pass a value from another form.

    strsql = "select PrinterModel, PrinterName, IP_Address, Location from
    Printers where PrinterName = ' & <% =Request.Form(npName) %> & ')"
     
    dthmtlgod, Oct 8, 2004
    #1
    1. Advertising

  2. dthmtlgod wrote:
    > I am getting a syntax error on my SQL statement, not sure if I am
    > doing this right. i am trying to pass a value from another form.
    >
    > strsql = "select PrinterModel, PrinterName, IP_Address, Location from
    > Printers where PrinterName = ' & <% =Request.Form(npName) %> & ')"


    You have a closing parenthesis without an opening parenthesis. Using

    response.write strsql

    would make this easy to see.



    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Oct 8, 2004
    #2
    1. Advertising

  3. dthmtlgod

    CJM Guest

    "dthmtlgod" <> wrote in message
    news:%23hDM$...
    > I am getting a syntax error on my SQL statement, not sure if I am doing

    this
    > right. i am trying to pass a value from another form.
    >
    > strsql = "select PrinterModel, PrinterName, IP_Address, Location from
    > Printers where PrinterName = ' & <% =Request.Form(npName) %> & ')"
    >


    Try:

    strsql = "select PrinterModel, PrinterName, IP_Address, Location from
    Printers where PrinterName = ' " & Request.Form(npName) & " ' "

    I've put spaces around the single quotes for clarity, but you can remove
    them in your code.

    CJM
     
    CJM, Oct 8, 2004
    #3
  4. dthmtlgod

    dthmtlgod Guest

    OK. Thank you Bob.

    That corrected the syntax error problem, however, it is not recognizing the
    =Request.Form(npName) value. Do I need to set this as a value and pass it?


    "Bob Barrows [MVP]" <> wrote in message
    news:%...
    > dthmtlgod wrote:
    > > I am getting a syntax error on my SQL statement, not sure if I am
    > > doing this right. i am trying to pass a value from another form.
    > >
    > > strsql = "select PrinterModel, PrinterName, IP_Address, Location from
    > > Printers where PrinterName = ' & <% =Request.Form(npName) %> & ')"

    >
    > You have a closing parenthesis without an opening parenthesis. Using
    >
    > response.write strsql
    >
    > would make this easy to see.
    >
    >
    >
    > Bob Barrows
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
     
    dthmtlgod, Oct 8, 2004
    #4
  5. dthmtlgod

    dthmtlgod Guest

    CJM,

    That is giving me the below error

    Error Type:
    Request object, ASP 0102 (0x80004005)
    The function expects a string as input.


    "CJM" <> wrote in message
    news:...
    >
    > "dthmtlgod" <> wrote in message
    > news:%23hDM$...
    > > I am getting a syntax error on my SQL statement, not sure if I am doing

    > this
    > > right. i am trying to pass a value from another form.
    > >
    > > strsql = "select PrinterModel, PrinterName, IP_Address, Location from
    > > Printers where PrinterName = ' & <% =Request.Form(npName) %> & ')"
    > >

    >
    > Try:
    >
    > strsql = "select PrinterModel, PrinterName, IP_Address, Location from
    > Printers where PrinterName = ' " & Request.Form(npName) & " ' "
    >
    > I've put spaces around the single quotes for clarity, but you can remove
    > them in your code.
    >
    > CJM
    >
    >
     
    dthmtlgod, Oct 8, 2004
    #5
  6. dthmtlgod

    dthmtlgod Guest

    Nevermind, I figured it out myself.

    Needs quotes around ("npName")

    Should have caught that in the first place.

    "CJM" <> wrote in message
    news:...
    >
    > "dthmtlgod" <> wrote in message
    > news:%23hDM$...
    > > I am getting a syntax error on my SQL statement, not sure if I am doing

    > this
    > > right. i am trying to pass a value from another form.
    > >
    > > strsql = "select PrinterModel, PrinterName, IP_Address, Location from
    > > Printers where PrinterName = ' & <% =Request.Form(npName) %> & ')"
    > >

    >
    > Try:
    >
    > strsql = "select PrinterModel, PrinterName, IP_Address, Location from
    > Printers where PrinterName = ' " & Request.Form(npName) & " ' "
    >
    > I've put spaces around the single quotes for clarity, but you can remove
    > them in your code.
    >
    > CJM
    >
    >
     
    dthmtlgod, Oct 8, 2004
    #6
  7. dthmtlgod

    CJM Guest

    Yep, missed that... sorry

    "dthmtlgod" <> wrote in message
    news:%23M1$...
    > Nevermind, I figured it out myself.
    >
    > Needs quotes around ("npName")
    >
    > Should have caught that in the first place.
     
    CJM, Oct 8, 2004
    #7
    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. Nathan Sokalski

    SQL syntax error in INSERT INTO statement

    Nathan Sokalski, Jul 1, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    14,617
    ahmed_samir
    Sep 3, 2010
  2. Maximus

    Syntax Error in SQL Update Statement

    Maximus, Feb 26, 2007, in forum: ASP General
    Replies:
    3
    Views:
    134
    Bob Barrows [MVP]
    Feb 26, 2007
  3. Ken Bloom
    Replies:
    3
    Views:
    213
  4. Replies:
    1
    Views:
    85
    Frederick Cheung
    Jan 17, 2008
  5. Mark Richards
    Replies:
    3
    Views:
    316
    Tad McClellan
    Nov 18, 2007
Loading...

Share This Page