I am trying to store a database name in a variable:
DECLARE @SQLString varchar(max)
DECLARE @DBIn varchar(50)
SET @DBIn ='myDB'
SET @SQLString = 'USE ' + @DBIn
select @SQLString
EXEC(@SQLString)
There are no errors when I execute this code but it does not actually works (the database does not change as it would if I just run a USE [myDB]).