We have a system (based on MS SQL 2008 R2) that has several "input" databases and one "output" database. I would like to write a query that will be read from the output database, and JOINit is to the data in one of the source databases. However, the source table can be one or more separate tables :( The name of the source database is included in the output database, ideally I would like to do something like the following (pseudo-SQL ahoy)
select o.[UID]
,o.[description]
,i.[data]
from [output].dbo.[description] as o
left join (select [UID]
,[data]
from
[output.sourcedb].dbo.datatable
) as i
on i.[UID] = o.[UID];
Is there a way to do something like the above - βdynamicallyβ specify the database and table to merge each row in the query?
source
share