SQL Statement Error?!

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

    SQL Statement Error?!

    Hi,

    Im trying to use a sesson statement within an SQL Statement:

    sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Compan y") &
    ""

    And get the error:

    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
    [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
    /numberlist.asp, line 31

    Anyone got any ideas? Surely this can only be something basic?

    TIA
    Oli


  • Ray at

    #2
    Re: SQL Statement Error?!

    sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Compan y")

    RESPONSE.WRITE SQL
    RESPONSE.END

    What does that show you?

    Ray at work


    "Oli" <oli@NOSPAMoliw oods.co.uk> wrote in message
    news:bqks2u$e7k $1@sparta.btint ernet.com...[color=blue]
    > Hi,
    >
    > Im trying to use a sesson statement within an SQL Statement:
    >
    > sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Compan y") &
    > ""
    >
    > And get the error:
    >
    > Error Type:
    > Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
    > [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
    > /numberlist.asp, line 31
    >
    > Anyone got any ideas? Surely this can only be something basic?
    >
    > TIA
    > Oli
    >
    >[/color]


    Comment

    • Oli

      #3
      Re: SQL Statement Error?!

      SELECT * FROM tblNumbers WHERE AllocatedTo=Alt ernateMedia

      Which is correct! Just noticed that the error is not with that line....
      Line 33 is:

      rs.Open sql, cn

      What does "Expected 1" mean?

      Thanks!
      Oli



      "Ray at <%=sLocation% >" <myfirstname at lane34 dot com> wrote in message
      news:emui3pauDH A.1224@TK2MSFTN GP09.phx.gbl...[color=blue]
      > sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Compan y")
      >
      > RESPONSE.WRITE SQL
      > RESPONSE.END
      >
      > What does that show you?
      >
      > Ray at work
      >
      >
      > "Oli" <oli@NOSPAMoliw oods.co.uk> wrote in message
      > news:bqks2u$e7k $1@sparta.btint ernet.com...[color=green]
      > > Hi,
      > >
      > > Im trying to use a sesson statement within an SQL Statement:
      > >
      > > sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Compan y")[/color][/color]
      &[color=blue][color=green]
      > > ""
      > >
      > > And get the error:
      > >
      > > Error Type:
      > > Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
      > > [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected[/color][/color]
      1.[color=blue][color=green]
      > > /numberlist.asp, line 31
      > >
      > > Anyone got any ideas? Surely this can only be something basic?
      > >
      > > TIA
      > > Oli
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Mike D

        #4
        Re: SQL Statement Error?!

        This SELECT * FROM tblNumbers WHERE AllocatedTo=Alt ernateMedia isn't correct
        it should be
        SELECT * FROM tblNumbers WHERE AllocatedTo='Al ternateMedia'

        And don't use select * in production code

        Mike

        "Oli" <oli@NOSPAMoliw oods.co.uk> wrote in message
        news:bqksvp$hss $1@sparta.btint ernet.com...[color=blue]
        > SELECT * FROM tblNumbers WHERE AllocatedTo=Alt ernateMedia
        >
        > Which is correct! Just noticed that the error is not with that line....
        > Line 33 is:
        >
        > rs.Open sql, cn
        >
        > What does "Expected 1" mean?
        >
        > Thanks!
        > Oli
        >
        >
        >
        > "Ray at <%=sLocation% >" <myfirstname at lane34 dot com> wrote in message
        > news:emui3pauDH A.1224@TK2MSFTN GP09.phx.gbl...[color=green]
        > > sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Compan y")
        > >
        > > RESPONSE.WRITE SQL
        > > RESPONSE.END
        > >
        > > What does that show you?
        > >
        > > Ray at work
        > >
        > >
        > > "Oli" <oli@NOSPAMoliw oods.co.uk> wrote in message
        > > news:bqks2u$e7k $1@sparta.btint ernet.com...[color=darkred]
        > > > Hi,
        > > >
        > > > Im trying to use a sesson statement within an SQL Statement:
        > > >
        > > > sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" &[/color][/color][/color]
        Session("Compan y")[color=blue]
        > &[color=green][color=darkred]
        > > > ""
        > > >
        > > > And get the error:
        > > >
        > > > Error Type:
        > > > Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
        > > > [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected[/color][/color]
        > 1.[color=green][color=darkred]
        > > > /numberlist.asp, line 31
        > > >
        > > > Anyone got any ideas? Surely this can only be something basic?
        > > >
        > > > TIA
        > > > Oli
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Bob Barrows

          #5
          Re: SQL Statement Error?!

          Oli wrote:[color=blue]
          > SELECT * FROM tblNumbers WHERE AllocatedTo=Alt ernateMedia
          >
          > Which is correct![/color]

          No, it is not correct. Strings need to be delimited in queries.This is
          correct:
          SELECT * FROM tblNumbers WHERE AllocatedTo='Al ternateMedia'
          [color=blue]
          > Just noticed that the error is not with that
          > line.... Line 33 is:
          >
          > rs.Open sql, cn
          >
          > What does "Expected 1" mean?[/color]

          That's not the whole error message. The whole message is "Too few
          parameters. Expected 1."

          Because you did not delimit the word AlternateMedia, Jet looked for a field
          named AlternateMedia in your table. When it did not find one, it treated
          AlternateMedia as a parameter. Since you did not provide a value for the
          parameter, it returned the error you reported. It's "expecting" a value for
          "1" parameter.

          If you had copied and pasted that query from the browser window into the SQL
          View of the Access Query Builder and tried to run it, you would have been
          prompted for a value for AlternateMedia. (this is how you should debug your
          queries)

          Your code should be changed to:

          sql = "SELECT * FROM tblNumbers WHERE AllocatedTo='" & _
          Session("Compan y") & "'"


          Better yet, instead of using dynamic sql, you should use a saved parameter
          query. A Google search should find plenty oif examples of this.

          HTH,
          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

          • Bhaskardeep Khaund

            #6
            Re: SQL Statement Error?!

            Hi,

            Change your SQL statement to this:-
            sql = "SELECT * FROM tblNumbers WHERE AllocatedTo='" & Session("Compan y") &"'"

            Because, tour AllocatedTo field must be a VarChar or Char data field. But you wnat to enter a Numeric data into it.

            Hope this helps.

            Bhaskardeep Khaund

            Comment

            • Oli

              #7
              Re: SQL Statement Error?!

              Thanks Guys!


              "Bob Barrows" <reb01501@NOyah oo.SPAMcom> wrote in message
              news:OFsXk6auDH A.2544@TK2MSFTN GP09.phx.gbl...[color=blue]
              > Oli wrote:[color=green]
              > > SELECT * FROM tblNumbers WHERE AllocatedTo=Alt ernateMedia
              > >
              > > Which is correct![/color]
              >
              > No, it is not correct. Strings need to be delimited in queries.This is
              > correct:
              > SELECT * FROM tblNumbers WHERE AllocatedTo='Al ternateMedia'
              >[color=green]
              > > Just noticed that the error is not with that
              > > line.... Line 33 is:
              > >
              > > rs.Open sql, cn
              > >
              > > What does "Expected 1" mean?[/color]
              >
              > That's not the whole error message. The whole message is "Too few
              > parameters. Expected 1."
              >
              > Because you did not delimit the word AlternateMedia, Jet looked for a[/color]
              field[color=blue]
              > named AlternateMedia in your table. When it did not find one, it treated
              > AlternateMedia as a parameter. Since you did not provide a value for the
              > parameter, it returned the error you reported. It's "expecting" a value[/color]
              for[color=blue]
              > "1" parameter.
              >
              > If you had copied and pasted that query from the browser window into the[/color]
              SQL[color=blue]
              > View of the Access Query Builder and tried to run it, you would have been
              > prompted for a value for AlternateMedia. (this is how you should debug[/color]
              your[color=blue]
              > queries)
              >
              > Your code should be changed to:
              >
              > sql = "SELECT * FROM tblNumbers WHERE AllocatedTo='" & _
              > Session("Compan y") & "'"
              >
              >
              > Better yet, instead of using dynamic sql, you should use a saved parameter
              > query. A Google search should find plenty oif examples of this.
              >
              > HTH,
              > 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

              Working...