Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Dynamically changing database contexts

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-21 : 22:27:39
Shawn B writes "I am attempting to build a T-SQL script to switch databases based on a desired environment (Dev, Test, etc.).

What I would like to do is something like:

declare @db varchar(32)
set @db = 'Dev'
use @db


Obviously this doesn't work. Nor does:

exec sp_executesql 'use Dev'

because the database switch only lasts as long as the EXEC runs and I am placed back where I was before the EXEC.


So, how can I dynamically make the database switch?


Thanks,
Shawn."

Nazim
A custom title

1408 Posts

Posted - 2002-04-22 : 01:23:24
there has been a pretty good discussion on this . check this http://www.sqlteam.com/Forums/topic.asp?TOPIC_ID=13082

--------------------------------------------------------------
Go to Top of Page
   

- Advertisement -