|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, March 28, 2013 7:38 AM
Points: 894,
Visits: 317
|
|
| Comments posted to this topic are about the item Go go go?
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, April 18, 2013 10:05 PM
Points: 38,
Visits: 72
|
|
"G0 x" means run the above batch x times.
Wouldn't that be, "GO x" means return the value x, as the only [and unnamed] column, in the only row of the resultset returned? Or is there some way to "run the above batch" NULL times, that I don't know about?
An interesting question (even if slightly sick and twisted, from a naming convention perspective) but lost it on the back stretch.
-MM
The Black Knight ALWAYS triumphs. Have at you!
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, March 28, 2013 7:38 AM
Points: 894,
Visits: 317
|
|
Try running something like
SELECT 1 AS A GO 3
This will return three resultset with one row and one column each (containing a 1).
In the example however,
GO 3;
should have ran the procedure with 3 as an argument. For some reason this just gives "Fatal parsing error while parsing 'GO' in my ssms (a bit odd since running the proc by executing GO; works fine).
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, November 30, 2012 1:52 AM
Points: 1,116,
Visits: 602
|
|
Such stored procedures are great for confusing anyone who needs to debug your code :)
Ronald
Ronald Hensbergen
Help us, help yourself... Post data so we can read and use it: http://www.sqlservercentral.com/articles/Best+Practices/61537/ ------------------------------------------------------------------------- 2+2=5 for significant large values of 2
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Wednesday, June 12, 2013 11:17 AM
Points: 9,855,
Visits: 9,376
|
|
Good one. I got everything else right, except that I missed that "GO;" would correctly execute the "GO" sproc (since it usually returns the aforementioned error).
By the way, I think that the answer could better explain the SSMS will only intercept the "GO [n]" if it is the first thing (or only thing?) on the line.
-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung Proactive Performance Solutions, Inc. "Performance is our middle name."
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Wednesday, June 12, 2013 11:17 AM
Points: 9,855,
Visits: 9,376
|
|
mmcginty (8/24/2008)
"G0 x" means run the above batch x times. Wouldn't that be, "GO x" means return the value x, as the only [and unnamed] column, in the only row of the resultset returned? Or is there some way to "run the above batch" NULL times, that I don't know about?
No, the author has it correct. "x" defaults to one (1).
-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung Proactive Performance Solutions, Inc. "Performance is our middle name."
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 3:47 PM
Points: 428,
Visits: 626
|
|
Here's my interpretation of what happens. Note if you select and execute the lines by themselves you get different results than you do if you combine them into a batch.
1 CREATE PROC GO @GO int=NULL AS SELECT @GO -- Start a new batch 2 GO -- This GO terminates procedure definition batch 3 GO; -- Begin a new batch 4 GO 3 -- Is this a SQLCMD? Ignored as a batch terminator because of the 3? Start loop. 5 GO -- Terminate the batch 6 EXECUTE('GO 3') -- Begin a new batch 7 GO 3 -- Is this a SQLCMD? Ignored as a batch terminator because of the 3? Start loop. 8 GO -- Terminate the batch 9 DROP PROC GO -- Start a new batch to drop the proc 10 GO -- Terminate the batch dropping the procedure
So we have Batch 1 lines 1 and 2 -- Define the proc Batch 2 lines 3 - 5 -- Execute the proc with no parm 3 times Batch 3 lines 6 - 8 -- Execute the proc with parm 3 times Batch 4 lines 9 and 10 -- Drop the proc.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, March 28, 2013 7:38 AM
Points: 894,
Visits: 317
|
|
Actually the "GO"'s at 5 and 8 does nothing but terminates an empty batch (since it is already terminated by the "GO 3"=terminate and run thrice). I beleive "GO 3" is something parsed and executed by SSMS alone and not SQLCMD?
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 3:47 PM
Points: 428,
Visits: 626
|
|
Actually that's what puzzled me. BOL says that GO is not a T-Sql command but a command recognized by Sqlcmd, Osql, and the SSMS Code Editor. It also says that nothing can appear on the line with a GO except comments. Then in the doc for Sqlcmd it shows a GO with a Count. [:]go [count] It's iteresting that for the go command in Sqlcmd they show the colon as optional but not for the other commands.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, June 11, 2013 2:08 PM
Points: 2,121,
Visits: 2,226
|
|
That was a cool, tricky question.
I got this in Query Analyzer (SQL 2000):
Server: Msg 170, Level 15, State 1, Line 2 Line 2: Incorrect syntax near 'GO'. Server: Msg 170, Level 15, State 1, Line 2 Line 2: Incorrect syntax near 'GO'.
but the code given did work in SSMS.
Thanks, werbunner
------------------- "The chemistry must be respected." - Walter White
"A SQL query walks into a bar and sees two tables. He walks up to them and says 'Can I join you?'" Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
|
|
|
|