Make Table Dynamic Table Name using INTO

E

excelCPA

Is there a way to write a Make Table query with dynamic table name?

For example, I want my query to make a table titled Results_MMDDYY,
where the MMDDYY is fully dynamic based on the date that I run the
query.

SELECT USER_ID, LOGIN_DATE, INTO [Results_]& Now()

The above line of SQL doesn't execute, but is there a way to do this
in the SQL editor (not in VBA)?
 
B

Bob Barrows

excelCPA said:
Is there a way to write a Make Table query with dynamic table name?

For example, I want my query to make a table titled Results_MMDDYY,
where the MMDDYY is fully dynamic based on the date that I run the
query.

SELECT USER_ID, LOGIN_DATE, INTO [Results_]& Now()

The above line of SQL doesn't execute, but is there a way to do this
in the SQL editor (not in VBA)?

No.
You have to use VBA to dynamically create the sql.
 
J

John W. Vinson

Is there a way to write a Make Table query with dynamic table name?

For example, I want my query to make a table titled Results_MMDDYY,
where the MMDDYY is fully dynamic based on the date that I run the
query.

SELECT USER_ID, LOGIN_DATE, INTO [Results_]& Now()

The above line of SQL doesn't execute, but is there a way to do this
in the SQL editor (not in VBA)?

No. You'll need to actually construct the SQL string and then execute it.

Note that this would be a HORRIBLE idea - storing data in a tablename is very
bad design. It's not searchable, it bloats your database, and it's
unnecessary; you could and should instead store the data in a table with a
datefield and use a Query to dynamically select any day's subset of the data.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top