Include Table name in Query result?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table which is generated initially by a make table query and then
append queries based on other tables thus includes info from several
different tables. Is it possible to store the source table name within the
new table?

Tx - Sheila
 
Hi, Sheila.

Yes. Modify the Make Table query to include a new column, SourceTable. For
example:

SELECT *, "tblOrders" AS SourceTable INTO tblArchive
FROM tblOrders;

.. . . where tblOrders is the source table, tblArchive is the new table to be
created, and SourceTable is the name of the field that will hold the name of
the source table. Every record inserted into this table at this time will
have tblOrders in the SourceTable field. Subsequent append queries can be
altered so that the SourceTable column is also added in the same way. For
example:

INSERT INTO tblArchive
SELECT *, "tblCancelled" AS SourceTable
FROM tblCancelled;

.. . . where tblCancelled is the name of the source table for these appended
records.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Sheila D said:
I have a table which is generated initially by a make table query and
then append queries based on other tables thus includes info from
several different tables. Is it possible to store the source table
name within the new table?

You'd need to modify your append queries to include a literal field
specifying the table name. And of course, you'd need to modify the
make-table query to create the field to receive that value.
 
Back
Top