Syntax Error on SQL statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dthmtlgod

    Syntax Error on SQL statement

    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(n pName) %> & ')"



  • Bob Barrows [MVP]

    #2
    Re: Syntax Error on SQL statement

    dthmtlgod wrote:[color=blue]
    > 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(n pName) %> & ')"[/color]

    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.


    Comment

    • CJM

      #3
      Re: Syntax Error on SQL statement


      "dthmtlgod" <doug.vandermar k@netzero.net> wrote in message
      news:%23hDM$NUr EHA.3868@TK2MSF TNGP15.phx.gbl. ..[color=blue]
      > I am getting a syntax error on my SQL statement, not sure if I am doing[/color]
      this[color=blue]
      > right. i am trying to pass a value from another form.
      >
      > strsql = "select PrinterModel, PrinterName, IP_Address, Location from
      > Printers where PrinterName = ' & <% =Request.Form(n pName) %> & ')"
      >[/color]

      Try:

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

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

      CJM


      Comment

      • dthmtlgod

        #4
        Re: Syntax Error on SQL statement

        OK. Thank you Bob.

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


        "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
        news:%23JFtCUUr EHA.1152@TK2MSF TNGP11.phx.gbl. ..[color=blue]
        > dthmtlgod wrote:[color=green]
        > > 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(n pName) %> & ')"[/color]
        >
        > 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.
        >
        >[/color]


        Comment

        • dthmtlgod

          #5
          Re: Syntax Error on SQL statement

          CJM,

          That is giving me the below error

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


          "CJM" <cjmnews04@news groups.nospam> wrote in message
          news:uSXGuVUrEH A.3324@TK2MSFTN GP15.phx.gbl...[color=blue]
          >
          > "dthmtlgod" <doug.vandermar k@netzero.net> wrote in message
          > news:%23hDM$NUr EHA.3868@TK2MSF TNGP15.phx.gbl. ..[color=green]
          > > I am getting a syntax error on my SQL statement, not sure if I am doing[/color]
          > this[color=green]
          > > right. i am trying to pass a value from another form.
          > >
          > > strsql = "select PrinterModel, PrinterName, IP_Address, Location from
          > > Printers where PrinterName = ' & <% =Request.Form(n pName) %> & ')"
          > >[/color]
          >
          > Try:
          >
          > strsql = "select PrinterModel, PrinterName, IP_Address, Location from
          > Printers where PrinterName = ' " & Request.Form(np Name) & " ' "
          >
          > I've put spaces around the single quotes for clarity, but you can remove
          > them in your code.
          >
          > CJM
          >
          >[/color]


          Comment

          • dthmtlgod

            #6
            Re: Syntax Error on SQL statement

            Nevermind, I figured it out myself.

            Needs quotes around ("npName")

            Should have caught that in the first place.

            "CJM" <cjmnews04@news groups.nospam> wrote in message
            news:uSXGuVUrEH A.3324@TK2MSFTN GP15.phx.gbl...[color=blue]
            >
            > "dthmtlgod" <doug.vandermar k@netzero.net> wrote in message
            > news:%23hDM$NUr EHA.3868@TK2MSF TNGP15.phx.gbl. ..[color=green]
            > > I am getting a syntax error on my SQL statement, not sure if I am doing[/color]
            > this[color=green]
            > > right. i am trying to pass a value from another form.
            > >
            > > strsql = "select PrinterModel, PrinterName, IP_Address, Location from
            > > Printers where PrinterName = ' & <% =Request.Form(n pName) %> & ')"
            > >[/color]
            >
            > Try:
            >
            > strsql = "select PrinterModel, PrinterName, IP_Address, Location from
            > Printers where PrinterName = ' " & Request.Form(np Name) & " ' "
            >
            > I've put spaces around the single quotes for clarity, but you can remove
            > them in your code.
            >
            > CJM
            >
            >[/color]


            Comment

            • CJM

              #7
              Re: Syntax Error on SQL statement

              Yep, missed that... sorry

              "dthmtlgod" <doug.vandermar k@netzero.net> wrote in message
              news:%23M1$yeUr EHA.2900@TK2MSF TNGP12.phx.gbl. ..[color=blue]
              > Nevermind, I figured it out myself.
              >
              > Needs quotes around ("npName")
              >
              > Should have caught that in the first place.[/color]


              Comment

              Working...