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 |
|
meboz
Starting Member
1 Post |
Posted - 2006-07-13 : 19:47:05
|
| Hi all,im new to this forum.I need to execute something along these lines but it doesnt wanna workdeclare @sql varchar(50)declare @db varchar(20)set @db = 'some_database'set @sql = 'USE ' + @dbexecute (@sql)it runs but doesnt switch to some_database.thanks in advance |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-07-13 : 21:35:10
|
| it actually works but it doesn't set you to the database you specified because it is run in the context of the dynamic sqli'm not very good with words, better add another line in the dsql and see if it shows you the result you expect...set @sql='use ' + @db + ';select * from tablename'what are you trying to achieve? there must be some simpler way like cross database querying perhaps?--------------------keeping it simple... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-07-14 : 03:24:54
|
| As you are using Dynamic SQL, scope is over once it is executed. You need to use them in same scope as Jen suggestedMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|