I'm trying to switch the current database with a SQL statement. I have tried the following, but all attempts failed:
- USE @DatabaseName
- EXEC sp_sqlexec @Sql -- where @Sql = 'USE [' + @DatabaseName + ']'
To add a little more detail.
EDIT: I would like to perform several things on two separate database, where both are configured with a variable. Something like this:
USE Database1
SELECT * FROM Table1
USE Database2
SELECT * FROM Table2