How to change the database with the name of the base stored in variable ?; Do the following code, however, do not change the database.
DECLARE @inicio VARCHAR (100)
DECLARE @bdname VARCHAR (100)
DECLARE @usedb VARCHAR (100)
SET @inicio = (
SELECT
MIN(dbid)
FROM
sysdatabases
WHERE name IS NOT NULL
and name not in ('master','tempdb','model','msdb','ReportServer','ReportServerTempDB'))
SET @bdname = (
select name from sysdatabases
where dbid = @inicio )
print @bdname
SET @usedb = 'USE ' + @bdname
EXEC (@usedb)
GO