Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

ASP question on SQL select Where on Autonumber field?

I have the following code in which I am trying to retrieve a record from an Access database using the autonumber field called "comp_it". Here's the code where I set up the SQL statement:

incmp = Request.QueryString("cmp_id")

inorg = Request.QueryString("origid")

incmplot = Request.QueryString("cmplot")

gsSQL = ""

gsSQL = gsSQL & "Select * FROM complaint WHERE comp_id = " & incmp

I know the comp_id field is numberic and I suspect the problem is the way the select statement is handling the incoming numberic vairable called incmp.

Any help / suggestions would be greatly appreciated!

Thanks!

Update:

Here's the error message I am getting:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'comp_id ='.

The reason for the code where there the "" is used to is to 'clear out' the SQL variable before I build it again. This probably isn't necessary but a good technique to insure I have an empty variable.

Thanks for looking!

Update 2:

Fixed it! The problem was in the variable naming as it was passed from the calling page the display page and then to the SQL statement. I think I 'spelled' it different everytime. The first answer I got had me rethinking about the names and I found the problem. THANKS!

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    Are you getting an error? Is the field comp_it or comp_id?

    write gsSQL to the browser and see if it is generating your select statement correctly. also, why do you have gsSQL = ""?

    Rather have it as follows: gsSQL = "Select * FROM complaint WHERE comp_id = " & incmp

    unless you have a valid reason?!

Still have questions? Get your answers by asking now.