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)
 SQL Query

Author  Topic 

loneregister
Starting Member

6 Posts

Posted - 2008-04-15 : 18:49:24
I wish to form a query that pulls data across databases dynamically.

For example:
I have a table with a field that indicates which database the data resides in. Based on the results of this field I wish to change which database the data is pulling from.

Something like

select dbasename, (select value from dbasename.dbo.othertable where x = y) from masterdatabase

Can anyone help me do this?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-16 : 01:25:06
Are all your databases in same server?
Go to Top of Page

loneregister
Starting Member

6 Posts

Posted - 2008-04-16 : 16:52:56
Yes.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-16 : 16:57:23
select s.dbasename, t.value from masterdatabase as s
left join dbasename.dbo.othertable as t on t.x = s.y



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -