g******o 发帖数: 4 | 1 Question:
Can I declare a variable to hold databases name and then use
the USE statement to switch between databases? Thanks.
I tried following approach but it won't work.
/*********************************
DECLARE @DatabaseName sysname
SET @DatabaseName = 'pubs'
USE @DatabaseName
*********************************/
Please help! |
a*****a 发帖数: 438 | 2 I don't think it's possible but I may be wrong too..
Can you use sp_defaultdb? what's your scenario?
【在 g******o 的大作中提到】 : Question: : Can I declare a variable to hold databases name and then use : the USE statement to switch between databases? Thanks. : I tried following approach but it won't work. : /********************************* : DECLARE @DatabaseName sysname : SET @DatabaseName = 'pubs' : USE @DatabaseName : *********************************/ : Please help!
|
a****o 发帖数: 37 | 3 try
exec ('use ' + @dbname)
【在 g******o 的大作中提到】 : Question: : Can I declare a variable to hold databases name and then use : the USE statement to switch between databases? Thanks. : I tried following approach but it won't work. : /********************************* : DECLARE @DatabaseName sysname : SET @DatabaseName = 'pubs' : USE @DatabaseName : *********************************/ : Please help!
|