September 9, 2008 at 11:21 pm
Comments posted to this topic are about the item What is the result ? (SQLServer 2005)
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- 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
September 10, 2008 at 2:57 am
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'.
September 10, 2008 at 3:51 am
probably Query Analyser doesn't recognize GO [count] syntax.
That proves that Query Analyser has it own syntax validation!
September 10, 2008 at 3:59 am
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
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- 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
September 10, 2008 at 4:06 am
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".
September 10, 2008 at 4:47 am
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'.
September 10, 2008 at 4:49 am
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
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- 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
September 10, 2008 at 5:41 am
This is the right way to execute the statement without using the counter.
September 10, 2008 at 7:31 am
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
September 10, 2008 at 7:34 am
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.
September 10, 2008 at 7:36 am
I did the same thing, edited the single line to two lines and it worked in QA. I was wondering if anyone had ideas on how this feature (GO 10) could be used...any thoughts?
September 10, 2008 at 7:44 am
imagine you need to generate 100 random numbers?
You can hit F5 100 times or use go 100.
September 10, 2008 at 7:45 am
barb.wendling (9/10/2008)
I did the same thing, edited the single line to two lines and it worked in QA. I was wondering if anyone had ideas on how this feature (GO 10) could be used...any thoughts?
Use SSMS if you want this to work !! (Not query analyser !)
e.g. for test purposes
create table mytable (id int not null identity(1,1) primary key,
col2 varchar(150) not null ,
col3 datetime not null default getdate() )
go
/* Fill table with 15000 rows */
insert into mytable (col2) values ('Initial load');
go 15000
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- 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
September 10, 2008 at 8:00 am
e.g. for test purposes
create table mytable (id int not null identity(1,1) primary key,
col2 varchar(150) not null ,
col3 datetime not null default getdate() )
go
/* Fill table with 15000 rows */
insert into mytable (col2) values ('Initial load');
go 15000
Careful ALZDBA, you'll have the RBAR police after you for suggesting something like that.;)
September 10, 2008 at 8:10 am
Boo hoo :crying: - I got it wrong because my local copy of BOL (SQL 2005) doesn't have the (count) syntax in it.
Viewing 15 posts - 1 through 15 (of 36 total)
You must be logged in to reply to this topic. Login to reply