Showing posts with label specifically. Show all posts
Showing posts with label specifically. Show all posts

Thursday, March 29, 2012

Consoldating data across databases

Thanks in advance for your help,
Is there an easy way to "link" data from one SQL database to another, preferably within a view?
More specifically, can one "link" to data from 2 seperate databases to a 3rd without importing the data?
Thanks,
LeeSure, if they are on the same server then just use 3-part naming convention in your queries:

select t1.f2, t2.f2, t3.f2
from db1.dbo.t t1
inner join db2.dbo.t t2 on t1.f1=t2.f1
inner join db3.dbo.t t3 on t1.f1=t3.f1 and t2.f1=t3.f1

...and if on different servers then create linked servers and use 4-part naming convention by preceeding the database name with the alias of the server.|||Thanks so much! It was so easy that I am embarrased