| Author |
Topic |
|
Tahumars
Starting Member
15 Posts |
Posted - 2009-10-28 : 17:48:42
|
I am running a set of queries dynamically, and would like to have GO in between them. However, I keep getting the errorquote: Msg 2812, Level 16, State 62, Line 1Could not find stored procedure 'GO'.
My query is quite large, so I tested using something as simple as:DECLARE @SQL AS VARCHAR(5000)DECLARE @GO AS VARCHAR(2)SET @GO = 'GO'SET @SQL = 'USE master'EXEC(@SQL)EXEC(@GO)SET @SQL = 'SELECT * FROM PRODUCTS'EXEC(@SQL)EXEC(@GO) The EXEC(@SQL) lines run successfully, but I get the above mentioned error once for each time I am calling EXEC(@GO)Is there another way of doing this or am i making a rookie mistake somewhere in there?Thanks in advance,Tahumars |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Tahumars
Starting Member
15 Posts |
Posted - 2009-10-28 : 18:32:33
|
| My reason for including GO's is to break up the script into smaller pieces. My script's structure is like:Huge UPDATEPrint('UPDATE 1 Done')GOHuge UPDATEPrint('UPDATE 2 Done')GOetc...So that while running the entire thing might take an hour, by splitting it into smaller batches I can know using the Prints (or the "# row(s) affected" message) when each UPDATE statement has completed. |
 |
|
|
Tahumars
Starting Member
15 Posts |
Posted - 2009-10-28 : 18:38:23
|
Just an addendum: My issue is that I'm creating these UPDATE statements dynamically. So what my script looks like is:declare @SQL as varchar(1000)declare @GO as varchar(2)set @GO = 'GO'set @SQL = 'UPDATE....'exec(@Sql)print('1 done')exec(@GO)set @SQL = 'UPDATE....'exec(@Sql)print('2 done')exec(@GO)Initially I tried doingdeclare @SQL as varchar(1000)set @SQL = 'UPDATE....'exec(@Sql)print('1 done')GOset @SQL = 'UPDATE....'exec(@Sql)print('2 done')GOBut that gave me the following error:quote: Msg 137, Level 15, State 1, Line 1Must declare the scalar variable "@SQL".
Which is odd because @SQL is deffinitely being declared. Does it need to be re-declared after every GO? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-29 : 02:21:04
|
| It you still dont understand what was suggesteddeclare @SQL as varchar(1000)set @SQL = 'UPDATE....'exec(@Sql)print('1 done')set @SQL = 'UPDATE....'exec(@Sql)print('2 done')MadhivananFailing to plan is Planning to fail |
 |
|
|
Tahumars
Starting Member
15 Posts |
Posted - 2009-10-29 : 10:56:50
|
Thanks for your attention so far, but I don't think I'm explaining myself correctly. If I run quote: declare @SQL as varchar(1000)set @SQL = 'UPDATE....'exec(@Sql)print('1 done')set @SQL = 'UPDATE....'exec(@Sql)print('2 done')
The print messages all show up at the same time when the entire script is finished. What I would like is to see the prints right after their corresponding query has completed. So assuming i have 6 updates that take 10 minutes each, instead of seeing all of the '1 done', '2 done' prints at once an hour after I start running the script, I would like to see '1 done' after the first query finishes in 10 minutes and '2 done' after the second query finishes 10 minutes after that.So to sum up, I'm not including GO to get my queries to execute, I'm including it to get them to execute individually as batches. Sorry, I know this is a bit convoluted and I'm not doing a great job of explaining myself. |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-10-29 : 13:57:24
|
| they already are individual batches. each exec() is an individual batch. this is why Tara said you don't need the GO statements |
 |
|
|
Tahumars
Starting Member
15 Posts |
Posted - 2009-10-29 : 14:06:23
|
| Hmmm, then I need to figure out why my prints are being delayed (all showing up at once at the end). I'll do some more investigation into that, I just assumed that I needed GO's. Thanks for the help everyone. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-30 : 02:30:46
|
quote: Originally posted by Tahumars Hmmm, then I need to figure out why my prints are being delayed (all showing up at once at the end). I'll do some more investigation into that, I just assumed that I needed GO's. Thanks for the help everyone.
You can't do what you are expecting. You will see prints only after the execution of all the statements. Why do you want to do this?MadhivananFailing to plan is Planning to fail |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2009-10-30 : 02:53:05
|
instead of printing, you could insert a row into a "progress" table and then periodically select from that table in another query window to check progress. elsasoft.org |
 |
|
|
|