SQL join from multiple tables

Posted by Kenny Anderson on Stack Overflow See other posts from Stack Overflow or by Kenny Anderson
Published on 2010-06-05T14:27:00Z Indexed on 2010/06/05 14:32 UTC
Read the original article Hit count: 221

Filed under:

Hi all

We've got a system (MS SQL 2008 R2-based) that has a number of "input" database and a one "output" database. I'd like to write a query that will read from the output DB, and JOIN it to data in one of the source DB. However, the source table may be one or more individual tables :( The name of the source DB is included in the output DB; ideally, I'd like to do something like the following (pseudo-SQL ahoy)

SELECT output.UID, output.description, input.data from output.dbo.description
LEFT JOIN
(SELECT input.UID, input.data FROM [output.sourcedb].dbo.datatable ) AS input
ON input.UID=output.UID

Is there any way to do something like the above - "dynamically" specify the database and table to be joined on for each row in the query?

© Stack Overflow or respective owner

Related posts about tsql