Parameter in a FROM clause?

  • Thread starter Thread starter Gerry Hickman
  • Start date Start date
G

Gerry Hickman

Hi,

Is it possible to use a parameter (or expression) in the FROM clause
instead of a hard coded table name? e.g.

PARAMETERS tName Text ( 255 );
SELECT *
FROM tName;

(This would allow the user to supply any table name and the query would
return all data from it).

When I try to do this I get an error saying a "parameter was found where
a table name was expected".

A second similar question; is it possible to do something like this
(assuming I have a table called "table22")

SELECT *
FROM "table" & "22";

Again, I can't get this to work.

I know how to do thid kind of thing with programming, but I'm trying to
learn how to do it with pure SQL.
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You have to do that in VBA. E.g.:

const SQL = "SELECT * FROM "
dim strTable as string
strTable = "table22"
dim strSQL as string
strSQL = SQL & strTable

' Then use the SQL string in a recordset or a querydef.

dim db as dao.database
dim qd as dao.querydef
set db = currentdb
set qd = db.querydef("<query name>")
qd.SQL = strSQL
qd.close

' Open the query in datasheet view
docmd.openquery "<query name>"

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA+AwUBQTzo4oechKqOuFEgEQIQpgCY0JJF3q+RVrB4GYeDMAAraFEhiwCfTCB/
gKOJfo+B1WeTo2n6AyV85H8=
=16iS
-----END PGP SIGNATURE-----
 
Back
Top