There are two databases in SQL Server 2005: One called ‘A’ and another one called ‘A_2’. ‘A’ is a variable name to be entered by the user, the ‘_2’ prefix for the second database is always known. (So databases could be ‘MyDB’ and ‘MyDB_2’, etc)
How to access the other database from within a stored procedure without knowing the actual name and without using the ‘exec’ statement?
You can try to use a new SQL Server 2005 feature, called synonyms.
You would need to CREATE SYNONYM, then compile and save the stored procedure using the synonym. This would leave you with the possibility to change the synonym ‘on the fly’ later on. Obviously, it would still be necessary to run the CREATE SYNONYM code as dynamic SQL.
To run CREATE SYNONYM, the user must be granted the respective permission, or have ALTER SCHEMA permission. Be sure to read more about synonyms before you go that route, there are a few strings attached.