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 1234»»»

What is the result ? (SQLServer 2005) Expand / Collapse
Author
Message
Posted Tuesday, September 9, 2008 11:21 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 12:40 AM
Points: 7,001, Visits: 8,439
Comments posted to this topic are about the item What is the result ? (SQLServer 2005)

Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #566602
Posted Wednesday, September 10, 2008 2:57 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, June 16, 2014 7:32 AM
Points: 1,327, Visits: 4,504
What happens seems to depend on the SQL Client/Options in use, rather than which version of SQL is at the back end.

The script executes 10 times if I run it in Management Studio, but...

When I run it in Query Analyser (against a SQL 2005 instance), I get an error:-

Server: Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'GO'.



Post #566679
Posted Wednesday, September 10, 2008 3:51 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, September 16, 2010 3:52 AM
Points: 78, Visits: 55
probably Query Analyser doesn't recognize GO [count] syntax.

That proves that Query Analyser has it own syntax validation!
Post #566700
Posted Wednesday, September 10, 2008 3:59 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 12:40 AM
Points: 7,001, Visits: 8,439
Keep in mind SSMS has some issues with e.g. char(13) resulting in a "syntax error near ...."

And off course you'll need to have the default 'go' for batch separator in your ssms settings.


Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #566707
Posted Wednesday, September 10, 2008 4:06 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, September 24, 2008 1:27 PM
Points: 350, Visits: 229
ALZDBA (9/10/2008)
Keep in mind SSMS has some issues with e.g. char(13) resulting in a "syntax error near ...."

And off course you'll need to have the default 'go' for batch separator in your ssms settings.


Im sorry but no, that is not asked in the question. The question asks what that piece of code does, and the result is:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'GO'.

I was going to choose the correct answer before I tested just to see what does happen, I should of done that as I would of got the answer "correct".
Post #566714
Posted Wednesday, September 10, 2008 4:47 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, September 16, 2010 3:52 AM
Points: 78, Visits: 55
skyline666 (9/10/2008)
ALZDBA (9/10/2008)
Keep in mind SSMS has some issues with e.g. char(13) resulting in a "syntax error near ...."

And off course you'll need to have the default 'go' for batch separator in your ssms settings.


Im sorry but no, that is not asked in the question. The question asks what that piece of code does, and the result is:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'GO'.

I was going to choose the correct answer before I tested just to see what does happen, I should of done that as I would of got the answer "correct".


In my case, it results in the batch run 10 times. I tested in my local instalation, with the default setting.

Probably you have some kind of customization that changed the setting for default batch seperator?

Example: If i change default separator to ";" got Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'GO'.
Post #566743
Posted Wednesday, September 10, 2008 4:49 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 12:40 AM
Points: 7,001, Visits: 8,439
You need to use SSMS (SQL 2005) to get the result aimed for with the question.
Apparently it's SSMS that puls this trick !

Indeed With Query Analyser, you'll get the syntax error.


-- Query analyser SQL2000
Server: Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'go'.



-- SSMS 2005
Beginning execution loop
Hey what's going on ?
Hey what's going on ?
Hey what's going on ?
Hey what's going on ?
Hey what's going on ?
Hey what's going on ?
Hey what's going on ?
Hey what's going on ?
Hey what's going on ?
Hey what's going on ?
Batch execution completed 10 times.




Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #566745
Posted Wednesday, September 10, 2008 5:41 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, January 8, 2010 12:14 AM
Points: 103, Visits: 25
This is the right way to execute the statement without using the counter.
Post #566776
Posted Wednesday, September 10, 2008 7:31 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, June 26, 2014 6:11 AM
Points: 1,330, Visits: 815
I for one, guessed wrong but I wanted to verify my answer before I submitted it. So, I highlighted and copied the code to SSMS and got the error, confirming my guess. When I was told I had the incorrect answer, I went back to SSMS and discovered that the two lines of code were mashed together on a single line:

print 'Hey what''s going on ?';GO 10 

This produced the error. However, when I separated it to two lines, it did work as expected by the question's author:

print 'Hey what''s going on ?';
GO 10

Post #566875
Posted Wednesday, September 10, 2008 7:34 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, April 17, 2014 7:01 AM
Points: 70, Visits: 69
In response to:
-- Query analyser SQL2000
Server: Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'go'.


Hi,
you are right, this technique does not works in SQL 2000. Its works version SQL 2005 and above and same statement works in sqlcmd without any error. It repeats the batch no of times as integer value mentioned after GO statement.
Post #566881
« Prev Topic | Next Topic »

Add to briefcase 1234»»»

Permissions Expand / Collapse