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 |
|
afaa
Starting Member
16 Posts |
Posted - 2008-06-10 : 19:25:08
|
| Hello SQL Team!I'm stuck at this problem for days and need help.The problem is with the GO keyword. I know the GO causes the batch to get executed and all local variables are lost. But I can't seem to find a work around. I would like each stored procedure to get executed in different batches.create table sql_cmd(cmd nvarchar(255))insert into sql_cmd(cmd) values('exec user_sp param1,''param2'')insert into sql_cmd(cmd) values('exec user_sp2 param1,''param2'')declare @sql nvarchar(255)declare c_sql cursor --small table peformance not a problem. Also open to other suggestionsfor select cmd from sqlcmdopen c_sqlfetch next from c_sqlinto @sqlwhile @@fetch_status = 0beginprint @sqlexec sp_executesql @sqlGOfetch next from c_sqlinto @sqlend |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-06-10 : 19:36:42
|
| Remove the GO and you should be good. Dynamic SQL executes in its own batch already, so GO isn't needed to start a new one.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
afaa
Starting Member
16 Posts |
Posted - 2008-06-10 : 19:48:28
|
| "Dynamic SQL executes in its own batch already"I did not know that. Thank you. Is there any documentation on that? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-06-11 : 09:52:23
|
| http://www.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|