We have a set of databases (development, QA and production, dev-foo & dev-bar, qa-foo & qa-bar and just foo & bar respectively).
Inside foo family of databases there's a view that should use respective bar database to do cross-database joins. In other words,
select f.*, b.* from foo f inner join <bar-db>.dbo.bar b on f.barid = b.id
The question is: is there any way I could write this script once and then have a database-level variable <bar-db> that would point to an appropriate "instance" of a bar database?