PDA

View Full Version : user defined table name


turnknuckle
11-06-2002, 05:45 PM
Greetings
Is it possible to get user input and use that value for a table name in a SQL query?
ie.

If strFirmType = "Stock Finance" Then
table1 = "stock_finance"
...
and then
...
strSQL2 = "SELECT * FROM table1 WHERE table1.ind_pref = 'All sectors considered - particularly Bio-Technology and Retail'"

If so what is the correct syntax - Do I need to wrap the variable - 'table1' or [table1] or something
I reckon Im using the wrong syntax...?

Thanks
Turnknuckle

BigDaddy
11-06-2002, 05:59 PM
Try:


strSQL2 = "SELECT * FROM " & table1 & "WHERE" & table1 ".ind_pref = 'All sectors considered - particularly Bio-Technology and Retail'"

table1 is your variable name.

turnknuckle
11-06-2002, 07:23 PM
Thanks man, its recognising the variable now, so if i take out the WHERE clause its reading from the db fine, but with the WHERE clause it gives me an 'expected end of statement' error at the '& table1".ind_pref' section of the statement...any ideas?
Cheers.
T.

Roelf
11-06-2002, 07:30 PM
maybe putting a space between the quote and the WHERE keyword: " WHERE "

whammy
11-06-2002, 11:43 PM
strSQL2 = "SELECT * FROM " & table1

:)