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. Advertisements

  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. Advertisements

  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. Advertisements

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. dna
    Replies:
    1
    Views:
    1,448
  2. sean
    Replies:
    2
    Views:
    688
    Kevin Spencer
    Dec 2, 2003
  3. Nathan Sokalski

    SQL syntax error in INSERT INTO statement

    Nathan Sokalski, Jul 1, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    15,075
    ahmed_samir
    Sep 3, 2010
  4. weiwei

    asp and sql statement in sql server db

    weiwei, Sep 22, 2004, in forum: ASP General
    Replies:
    3
    Views:
    362
    Jeff Cochran
    Sep 22, 2004
  5. Maximus

    Syntax Error in SQL Update Statement

    Maximus, Feb 26, 2007, in forum: ASP General
    Replies:
    3
    Views:
    214
    Bob Barrows [MVP]
    Feb 26, 2007
  6. Ken Bloom
    Replies:
    3
    Views:
    454
  7. Replies:
    1
    Views:
    140
    Frederick Cheung
    Jan 17, 2008
  8. Mark Richards
    Replies:
    3
    Views:
    483
    Tad McClellan
    Nov 18, 2007
Loading...