...

Asp & Sql

rah111
07-03-2002, 01:16 PM
Hi all.

I have a main.asp file calling list.asp with:

... list.asp?the_file&the_race ...

In list.asp I have two querystring requests as follows:

dbf_file=request.querystring(1)
race_str=request.querystring(2)

and an SQL statement as below:

Sql = "SELECT Rno, Tabno, Name, Starts, Wins, Second, Third, Bp, Jock, Weight FROM " & dbf_file

The problem is that I don't want all the records in the data table, but want to apply a WHERE condition to get only those records where race_str equals a variable number passed from main.asp. The data table itself is also variable and is passed from main.asp.

If I knew that the number (race_str) was 5 and that the data table to be accessed (dbf_file) was Test.dbf then I could use:

Sql = "SELECT Rno, Tabno, Name, Starts, Wins, Second, Third,
Bp, Jock, Weight FROM Test.dbf WHERE Rno = 5

However I don't, so I've tried:

Sql = "SELECT Rno, Tabno, Name, Starts, Wins, Second, Third, Bp, Jock, Weight FROM " & dbf_file " WHERE Rno = " & race_str

and I get the following error message:

"Microsoft VBScript compilation error - Expected end of statement"

How do I properly concatenate the explicit SQL statement with the variable values I obtain from the querystring requests?

Can someone help?

Thanks.

Russell.

ObiwanJebroni
07-03-2002, 01:28 PM
Sql = "SELECT Rno, Tabno, Name, Starts, Wins, Second, Third, Bp, Jock, Weight FROM " & dbf_file & " WHERE Rno = " & race_str

The correction is in bold.

rah111
07-04-2002, 12:16 AM
Thanks a lot Obiwan and Dave.

That works nicely.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum