Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Go go go?


Go go go?

Author
Message
anders-731262
anders-731262
SSC Eights!
SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)

Group: General Forum Members
Points: 999 Visits: 355
Comments posted to this topic are about the item Go go go?
mmcginty
mmcginty
SSC Rookie
SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)

Group: General Forum Members
Points: 46 Visits: 75
"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!
anders-731262
anders-731262
SSC Eights!
SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)

Group: General Forum Members
Points: 999 Visits: 355
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).
Ronald H
Ronald H
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1131 Visits: 609
Such stored procedures are great for confusing anyone who needs to debug your code Smile

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
RBarryYoung
RBarryYoung
SSCrazy Eights
SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)

Group: General Forum Members
Points: 9436 Visits: 9517
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."
RBarryYoung
RBarryYoung
SSCrazy Eights
SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)SSCrazy Eights (9.4K reputation)

Group: General Forum Members
Points: 9436 Visits: 9517
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."
DaveD-128295
DaveD-128295
SSC-Addicted
SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)

Group: General Forum Members
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.
anders-731262
anders-731262
SSC Eights!
SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)

Group: General Forum Members
Points: 999 Visits: 355
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?
DaveD-128295
DaveD-128295
SSC-Addicted
SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)SSC-Addicted (428 reputation)

Group: General Forum Members
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.
webrunner
webrunner
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3027 Visits: 3745
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

-------------------
"I love spending twice as long and working twice as hard to get half as much done!" – Nobody ever.
Ref.: http://www.adminarsenal.com/admin-arsenal-blog/powershell-how-to-write-your-first-powershell-script

"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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search