How to include a field showing table name in a UNION query?

How to include a field showing table name in a UNION query?

am 15.01.2008 16:03:22 von MLH

Have UNION query pulling & merging data from 3 tables.
Would like to show Name, Addr, City, State, Zip and table
name of source table. Dunno how.

Re: How to include a field showing table name in a UNION query?

am 15.01.2008 16:24:08 von Allen Browne

This kind of thing:

SELECT CustName, Addr, City, "tblCustomer" AS SourceTable
FROM tblCustomer
UNION ALL
SELECT SupplierName, Addr, City, "tblSupplier" AS SourceTable
FROM tblSupplier
UNION ...

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" wrote in message
news:gmipo3pj9uhhhvnta1bkejp0grpc4nq8i9@4ax.com...
> Have UNION query pulling & merging data from 3 tables.
> Would like to show Name, Addr, City, State, Zip and table
> name of source table. Dunno how.

Re: How to include a field showing table name in a UNION query?

am 15.01.2008 16:26:48 von MLH

Sorry for leaving out an important ingredient from the first OP.
Am looking for an SQL statement to reference the table name.
I realize I can hard-code the name to display in the query like this:

SELECT tblProspectsNCDMVdealerList.DealerID AS ID,
tblProspectsNCDMVdealerList.DealerName AS Company,
tblProspectsNCDMVdealerList.Contact AS Contact,
tblProspectsNCDMVdealerList.DealerAddr1 AS Address,
tblProspectsNCDMVdealerList.DealerCity AS City,
tblProspectsNCDMVdealerList.DealerState AS ST,
tblProspectsNCDMVdealerList.DealerZip AS Zip,
tblProspectsNCDMVdealerList.DealerPhn AS Phone,
tblProspectsNCDMVdealerList.DlrEmail AS EMail,
tblProspectsNCDMVdealerList.FollowUp, "tblProspectsNCDMVdealerList" AS
TBL
FROM tblProspectsNCDMVdealerList
WHERE (((tblProspectsNCDMVdealerList.FollowUp)=True))

UNION SELECT tblProspectsNCGarages.TowCoID AS ID,
tblProspectsNCGarages.TowCoName AS Company,
tblProspectsNCGarages.TowCoContact AS Contact,
tblProspectsNCGarages.TowCoAddrLine1 AS Address,
tblProspectsNCGarages.TowCoCity AS City,
tblProspectsNCGarages.TowCoState AS ST, tblProspectsNCGarages.TowCoZip
AS Zip, tblProspectsNCGarages.TowCoPhn AS Phone,
tblProspectsNCGarages.TowCoEmail AS EMail,
tblProspectsNCGarages.FollowUp, "tblProspectsNCGarages" AS TBL
FROM tblProspectsNCGarages
WHERE (((tblProspectsNCGarages.FollowUp)=True))
ORDER BY Company;

But I'm seeking an alternative.