|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 3:25 AM
Points: 1,165,
Visits: 731
|
|
Hardy21 (11/23/2010)
Try INSERT INTO # SELECT 'ASDF' GO 0 GO <ZERO> --- SQL doesn't throw any complilation error but when you execute the code, status bar should display: "Query completed with errors".
Nope, doesn't like the 0 (zero) either.
I think it is the old version of SQL... further investigation does seem to suggest it.
_____________________________________________________________________ "The difficult tasks we do immediately, the impossible takes a little longer"
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 8:52 AM
Points: 1,788,
Visits: 3,327
|
|
It's also worth mentioning that GO is not a T-SQL statement. It is a command only recognized by SSMS, sqlcmd and osql, so it can't be used in any T-SQL code that is not executed in any of the three applications mentioned. In other words, SQL Server does not know what GO is.
From BOL: "SQL Server utilities interpret GO as a signal that they should send the current batch of Transact-SQL statements to an instance of SQL Server. The current batch of statements is composed of all statements entered since the last GO, or since the start of the ad hoc session or script if this is the first GO."
Ref http://msdn.microsoft.com/en-us/library/ms188037.aspx
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: 2 days ago @ 7:11 AM
Points: 877,
Visits: 1,159
|
|
DougieCow (11/23/2010)
Hardy21 (11/23/2010)
Try INSERT INTO # SELECT 'ASDF' GO 0 GO <ZERO> --- SQL doesn't throw any complilation error but when you execute the code, status bar should display: "Query completed with errors". Nope, doesn't like the 0 (zero) either. I think it is the old version of SQL... further investigation does seem to suggest it. I have executed the code against SQL Server 2008 R2.
Thanks
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Monday, April 01, 2013 10:11 AM
Points: 576,
Visits: 27,680
|
|
Hardy21 (11/23/2010)
DougieCow (11/23/2010)
Hardy21 (11/23/2010)
Try INSERT INTO # SELECT 'ASDF' GO 0 GO <ZERO> --- SQL doesn't throw any complilation error but when you execute the code, status bar should display: "Query completed with errors". Nope, doesn't like the 0 (zero) either. I think it is the old version of SQL... further investigation does seem to suggest it. I have executed the code against SQL Server 2008 R2.
I have also executed on SQL Server 2008 R2. It gave "Query completed with errors" but no error message.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: 2 days ago @ 7:11 AM
Points: 877,
Visits: 1,159
|
|
Brigadur (11/23/2010)
Hardy21 (11/23/2010)
DougieCow (11/23/2010)
Hardy21 (11/23/2010)
Try INSERT INTO # SELECT 'ASDF' GO 0 GO <ZERO> --- SQL doesn't throw any complilation error but when you execute the code, status bar should display: "Query completed with errors". Nope, doesn't like the 0 (zero) either. I think it is the old version of SQL... further investigation does seem to suggest it. I have executed the code against SQL Server 2008 R2. I have also executed on SQL Server 2008 R2. It gave "Query completed with errors" but no error message. Correct. Also if you execute the: select * from # GO 0 then also it should display: "Query completed with errors" in status bar, and doesn't display any data in grid due to code is not executed.
Thanks
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Today @ 2:11 AM
Points: 9,378,
Visits: 6,473
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 6:55 AM
Points: 1,385,
Visits: 1,086
|
|
I think that this functionality of adding a count to the GO command is only available in SQL 2005 and up.
Thanks...Chris
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 8:52 AM
Points: 1,788,
Visits: 3,327
|
|
da-zero (11/23/2010)
Nils Gustav Stråbø (11/23/2010) It's also worth mentioning that GO is not a T-SQL statement. It is a command only recognized by SSMS, sqlcmd and osql, so it can't be used in any T-SQL code that is not executed in any of the three applications mentioned. In other words, SQL Server does not know what GO is.Hmm. I seem to recall that I have used GO in Execute SQL Tasks in SSIS without a problem. (Or does that fall in the 3 categories you mentioned, because I only know the first one  ) I just tested, and SSIS actually honors the GO command. Nice to know. Thanks
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:22 AM
Points: 5,244,
Visits: 7,059
|
|
Nice question, fairly basic. I agree that the # trickery is a bit unnecessary.
Minor bitching about the title and explanation:
1) GO is not a T-SQL statement. It's a batch seperator that most clients recognise and honor. But if you write your own C# client and have it send "GO" to SQL Server, you'll get a syntax error message, as SQL Server does not recognise GO as a valid keyword.
2) A very minor distinction - because GO is processed by the client, GO 100 will not simply execute the batch 100 times; it will send it 100 times. The result will be the same, but you get more network traffic and more parse and compile time. If you want to save on those resources, write a single batch with the logic to execute the statement 100 times.
DECLARE @i int = 1; WHILE @i <= 100 BEGIN; INSERT (...); SET @i += 1; END;
DougieCow (11/23/2010) (...) when I did actually try to run the code it didn't seem to like the "100"... I got...
(1 row(s) affected)
Server: Msg 170, Level 15, State 1, Line 3 Line 3: Incorrect syntax near '100'.
The code is identical... I'm running this on a SQL Server 2000 box, but I don't think that matters... The server does not matter, the client does. You need at least the SSMS version that ships with SQL Server 2005. It should work against any version server, as far as I know (but I never tried this).
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 9:31 AM
Points: 1,041,
Visits: 1,356
|
|
da-zero (11/23/2010) I like the point the question tried to make, namely using the GO statement as an instrument to loop, but I do not like the trickery with the # name. At first, I did not even notice the GO 100 statement, as I was focusing on the table name. So I'm confused what this question actually tried to do: teach us about GO n (mission accomplished), or about the various options for table names or was it just to trick people into choosing the wrong answer?
Agreed. That's why, for me, this question falls into the "good, but with incomplete explanation" category: I don't mind a question with 2 or more points to make, but you've got to make those points clear in your explanation. Add the explanation that # is an acceptable table name, and a resource explaining why, and this would be a good question.
|
|
|
|