March 24, 2005 at 4:39 pm
why does the first one work and the second does not?
declare @i int
set @i = 5
print @i
/*go*/
print @i
5
5
=================================================
declare @i int
set @i = 5
print @i
/*
go
*/
print @i
Server: Msg 113, Level 15, State 1, Line 4
Missing end comment mark '*/'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '*'.
Server: Msg 137, Level 15, State 1, Line 3
Must declare the variable '@i'.
March 24, 2005 at 6:39 pm
It is a known issue with regards to the batch seperator GO in a multiline comment. I don't have the KB article handy but if you look at MS code you will always find --GO to prevent. The parser sees GO in the string and sperates the batch there thus what you actual are running as far as the parser is concerned is this
Batch 1
declare @i int
set @i = 5
print @i
/*
Batch 2
*/
print @i
Try each that way and you will see.
March 24, 2005 at 6:45 pm
From BOL
Indicates user-provided text. The text between the /* and */ commenting characters is not evaluated by the server.
/* text_of_comment */
Comments can be inserted on a separate line or within a Transact-SQL statement. Multiple-line comments must be indicated by /* and */. A stylistic convention often used for multiple-line comments is to begin the first line with /*, subsequent lines with **, and end with */.
There is no maximum length for comments.
Note Including a GO command within a comment generates an error message.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply