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 2005 Forums
 Transact-SQL (2005)
 To get a column data which spanned multiple tables

Author  Topic 

mukkanti
Starting Member

9 Posts

Posted - 2008-06-12 : 05:08:27
All,
i am looking for a query which fetches data from column 'managerid' which spread across 20 tables,

Managerid colums is spread across 20 tables and i need only managerid data from all the tables available, data for managerid column will be different in each table.

can anyone help me regarding the same.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-12 : 05:16:17
Exec sp_msforeachtable 'if col_length(''?'',''Managerid'')>0
SELECT Managerid FROM ?'

or use

SELECT managerid from table1
UNION ALL
SELECT mangerid FROM Table2
....
UNION ALL
SELECT mangerid from Table20
Go to Top of Page

mukkanti
Starting Member

9 Posts

Posted - 2008-06-12 : 05:33:28
Hi,
Thanks , i got the data.
Go to Top of Page
   

- Advertisement -