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
 General SQL Server Forums
 New to SQL Server Programming
 Returning Table Name that Data was Queried From

Author  Topic 

cant2ny
Starting Member

20 Posts

Posted - 2010-02-02 : 12:21:18
Hey All,

I need to write a query to pull data from about 15-20 tables, the only problem is I'm also trying to return specifically what table the data was queried from. So along with the data contained in the table, I also want to return the table name itself in each row for each table.

Is there any easy way to do this? They are all user-defined tables. Thanks in advance for any help.

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-02-02 : 12:43:59
SELECT 'yourTable' as [table], * FROM yourTable;
Go to Top of Page
   

- Advertisement -