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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-09-19 : 07:41:36
|
| Carlos writes "I am trying to create a sp that would jump from one DB to another using the USE command. I built a string and then I tried to run EXECUTE(@SQLString) with no lock. This is the sample code I am using:declare @DBName varchar(200)declare @SQlString varchar(300)set @DBName='model'set @SQlString = 'use '+@DBNameexecute(@SQlString)Is there any way I can accomplish that?ThanksCarlos" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-19 : 07:51:03
|
| Changing DBName dynamically is not recommendedTry thisdeclare @DBName varchar(20)declare @SQlString varchar(300)set @DBName='model'set @SQlString = 'Select columns from '+@DBName+'..TableName'execute(@SQlString)MadhivananFailing to plan is Planning to fail |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2005-09-19 : 22:02:07
|
why do you need to "jump" from one db to another?you can cross-query with the appropriate permissions --------------------keeping it simple... |
 |
|
|
|
|
|