Click to See Complete Forum and Search --> : sql union


Replica
June 18th, 2006, 10:29 AM
When i use union in a sql query, can i get the table's name of the current record?

P.S
i'm working with mssql.

thanks in advance.

davide++
June 19th, 2006, 06:03 AM
Hi all,

A simple way to do this is adding in both queries a field that says which is the table.

For exemple:

SELECT COMPONENTE_ID, 'CPE' AS TABLE_NAME FROM CPE
UNION
SELECT COMPONENTE_ID, 'ADSL' AS TABLE_NAME FROM ADSL