Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to using string in query in ASP page?

Status
Not open for further replies.

longmatch

Programmer
Nov 1, 2001
406
I ran into a problem when I ran a query in my ASP page. My query works when it is run in ACCESS database. But it did not work in ASP page. Don't know why.
strSQLSummary = "SELECT Count(Prococedure) AS NOProcedure, category "
strSQLSummary = strSQLSummary & "FROM FORM_ID_198163500 GROUP BY category HAVING baylorID= "haijunw""

It looks like something is wrong with the string in HAVING clause.

If you can give me a explaination, that will be great.

Haijun
 
Use single quotes around your id value:

strSQLSummary = "SELECT Count(Prococedure) AS NOProcedure, category "
strSQLSummary = strSQLSummary & "FROM FORM_ID_198163500 GROUP BY category HAVING baylorID= 'haijunw'"

An easy way to debug your SQL statements is to print them to the screen before you execute them. This will allow you to see any errors in building the string before you send it to the database.

Here the problem was that you were trying to put double quotes within your string. ASP would have read the second double quote it came across as the end of the string.
 
Or (can't remember) if Access doesn't accept single quotes around strings, you can do something like

strSQLSummary = strSQLSummary & "FROM FORM_ID_198163500 GROUP BY category HAVING baylorID= ""haijunw"""

You unescape double quotes by doubling them. codestorm
Fire bad. Tree pretty. - Buffy
select * from population where talent > 'average'
You're not a complete programmer unless you know how to guess.
I hope I never consider myself an 'expert'.
<insert witticism here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top