Hi,
I have a stored procedure that I want to be able to select the database it runs against.
For example, I want to pass the name of the database to the stored procedure, then have it run against the tables in THAT database.
SET @usedb = 'USE ' + @dbname << passed-in parameter
e.g.) USE MY_DATABASE - as you would run this from Query Analyzer, except I want to run this in the stored procedure itself.
Can this be done, and if so - how?
I can't use EXEC @usedb - treats it like an sp call
Thanks
I have a stored procedure that I want to be able to select the database it runs against.
For example, I want to pass the name of the database to the stored procedure, then have it run against the tables in THAT database.
SET @usedb = 'USE ' + @dbname << passed-in parameter
e.g.) USE MY_DATABASE - as you would run this from Query Analyzer, except I want to run this in the stored procedure itself.
Can this be done, and if so - how?
I can't use EXEC @usedb - treats it like an sp call
Thanks