I am writing a stored procedure that will be gathering data from two very, similar databases. Where possible I would like to write one set of code and pass it parameters in order to specify the database name to use. I've discovered that the USE <database_name> statement will not work in stored procedures. I've tried every way I can think of to use a variable as part of the FROM clause in a SELECT to no avail. Is something like the following somehow possible?
Thanks in advance, Mark