Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Go go go? Expand / Collapse
Author
Message
Posted Saturday, August 23, 2008 8:16 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, August 18, 2014 6:13 AM
Points: 984, Visits: 350
Comments posted to this topic are about the item Go go go?
Post #557812
Posted Sunday, August 24, 2008 10:25 PM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 17, 2013 3:10 AM
Points: 40, Visits: 73
"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!
Post #557922
Posted Monday, August 25, 2008 2:30 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, August 18, 2014 6:13 AM
Points: 984, Visits: 350
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).
Post #558004
Posted Monday, August 25, 2008 4:02 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, October 9, 2013 5:08 AM
Points: 1,127, Visits: 603
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
Post #558033
Posted Monday, August 25, 2008 6:50 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Thursday, June 5, 2014 10:54 AM
Points: 9,902, Visits: 9,480
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."
Post #558091
Posted Monday, August 25, 2008 6:51 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Thursday, June 5, 2014 10:54 AM
Points: 9,902, Visits: 9,480
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."
Post #558094
Posted Monday, August 25, 2008 7:41 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Monday, July 1, 2013 2:25 PM
Points: 428, Visits: 627
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.
Post #558131
Posted Monday, August 25, 2008 7:51 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, August 18, 2014 6:13 AM
Points: 984, Visits: 350
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?
Post #558140
Posted Monday, August 25, 2008 8:24 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Monday, July 1, 2013 2:25 PM
Points: 428, Visits: 627
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.

Post #558168
Posted Monday, August 25, 2008 9:29 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 8:24 AM
Points: 2,351, Visits: 2,700
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


-------------------
"Operator! Give me the number for 911!" - Homer Simpson

"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
Post #558209
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse