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 |
bkpgamble
Starting Member
30 Posts |
Posted - 2006-10-09 : 07:21:48
|
I need to be able to switch DB in a cursor loopbut how do I use a variable to change the DB ?I tried this but dosent workUSE @DBNameWithSimpleLogAnnyone have an idea ? |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-09 : 07:27:47
|
set @mysqlcmd = 'USE ' + @DBNameWithSimpleLogEXEC (@mysqlcmd)Peter LarssonHelsingborg, Sweden |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-09 : 07:33:32
|
if you need to access a table from another database use the full namingselect *from db2.dbo.table KH |
 |
|
bkpgamble
Starting Member
30 Posts |
Posted - 2006-10-09 : 07:55:26
|
Peso solved it :)dident even consider using EXEC thanks |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
X002548
Not Just a Number
15586 Posts |
|
mr_mist
Grunnio
1870 Posts |
Posted - 2006-10-09 : 10:45:24
|
Remember that if you do use this approachset @mysqlcmd = 'USE ' + @DBNameWithSimpleLogEXEC (@mysqlcmd)Then the context is only changed for the duration of the EXEC, not for anything after that.-------Moo. :) |
 |
|
|
|
|