Forum Discussion
Multiple Databases in a dataset
You should be solve this more elegantly in SQL Server by using synonyms (see https://docs.microsoft.com/en-us/sql/relational-databases/synonyms/create-synonyms?view=sql-server-ver15)
These effectively work as sort short cut links. I think if you setup linked servers you can event create cross-server synonyms, but you'd need to be careful with these as they come with the same perform potential performance issues as referencing linked servers directly. However using them to link across databases in the same instance is less prone to issues (and has the same performance implications as using 3 part names). We typically put all our synonyms in their own schemas with a prefix of syn_ so that we can easily see that we are not referencing a local object
So you could do something like the following in TESTDB1 (notice that the reference to TESTDB2 is set once when you create the synonym)
CREATE SYNONYM syn_db2.Sales FOR TESTDB2.dbo.Sales;
Then your report just has to connect to TESTDB1 and could run the following query:
Select D.DeptDescription, S.Amount
from Dept D join syn_db2.Sales S
on D.DeptCode = S.DeptCode