I have a problem when creating a view:
In this view I select data from the selected database and join this with data from another database - this part works perfectly.
This is the part that does work:
SELECT tDb1.column1, tDb1.column2, tDb2.columnFromDb2
FROM tableFromDbInUse tDb1
JOIN db2.tableFromDb2 tDb2 ON tDb1.something = tDb2.something
I am looking for a way to exchange the second database without changing the statement in the view. Like "db2" would act as a prameter in a stored procedure @db2. @db2 would be an alias for a database name then that I can set somewhere else. In this way I could use the view in databases with different names but same structure, without amending all statements manually.
Is there any way to do this?
Here's the pseudocode that shall show what I try to achieve. I use @db2 for the "parameter" behaviour I am looking for:
SELECT tDb1.column1, tDb1.column2, tDb2.columnFromDb2
FROM tableFromDbInUse tDb1
JOIN @db2.tableFromDb2 tDb2 ON tDb1.something = tDb2.something