Re: Query analyzer and changing database on the fly?
- From: "Kalen Delaney" <replies@xxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 11 May 2006 08:22:20 -0700
Hi
Your exec works fine, but its scope is only the duration of the exec, so
when the exec is finished, you're back to the db you started in. You can
include more commands in the exec
('use ' + @db_name + ' <do some work in other db>')
You can find out your current database with db_name:
SELECT db_name()
--
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"Major" <lievonen@xxxxxxxxxxxxxxxxxx> wrote in message
news:%23Fskf0PdGHA.5048@xxxxxxxxxxxxxxxxxxxxxxx
How I can change database in the Query Analyzer on the fly if I have
database name in the @db_namd -variable?
I tried:
use master
exec ('use ' + @db_name) and it didn't cause any error messages, but it
still use master...
And how I can query "current database" in the QA?
.
- References:
- Query analyzer and changing database on the fly?
- From: Major
- Query analyzer and changing database on the fly?
- Prev by Date: Query analyzer and changing database on the fly?
- Next by Date: SQL 2000 + SQL 2005 Express Compatibility (restore SQL 2005 DB with 2000 DB)
- Previous by thread: Query analyzer and changing database on the fly?
- Next by thread: SQL 2000 + SQL 2005 Express Compatibility (restore SQL 2005 DB with 2000 DB)
- Index(es):
Relevant Pages
|