Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Union

Author  Topic 

ann
Posting Yak Master

220 Posts

Posted - 2007-02-08 : 18:19:15
Is there someway I can Identify which table a particular row is when I do a union? For ex., I have a simple union:
SELECT CID, CDescription
FROM Corporate
union

SELECT SID, CDescription
FROM Regional

When I get the result set, I need to know which tables they came from (either Corporate or Regional).
Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-02-08 : 18:23:22
SELECT CID, CDescription, 'From Corporate' AS WhichTable
FROM Corporate
union all
SELECT SID, CDescription, 'From Regional' AS WhichTable
FROM Regional

Or use an integer (1, 2).

Tara Kizer
Go to Top of Page
   

- Advertisement -