sql server - sql use statement with variable -


I am trying to switch the existing database with the SQL statement. I tried the following, but all attempts failed:

  1. USE @DatabaseName
  2. EXEC sp_sqlexec @sql - where @ sql = 'USE [' + + DatabaseName + ']]'

To add a little further detail.

EDIT: I want to do several things on two different databases, where both are configured with one variable i like something like this:

  Use Database 1 Select * Table 1 Use Database 2 Select * Table 2  


Comments