September 24, 2013 at 6:31 pm
Hugo Kornelis (9/24/2013)
L' Eomot Inversé (9/24/2013)
Interesting question.I knew the answer, but Jens-Peter's comment made me wonder: he's quite right, the behavious is not documented on the page referenced. Nor is it documented on the -- comment BOL page. I wonder if it is documented anywhere?
I think it is clearly documented.
The -- page specifies that the rest of the text until the end of the line is ignored.
The /* */ page specifies that the text between opening and closing mark is ignored, with the explicit exception that nested comments are recognised.
Add one and one together, and it is clear that /* ... */ is parsed for other /* and */ sequences, while -- ... (end of line) is not parsed at all.
On the -- BOL page we have the plain and simple statements (two sentences) "Use two hyphens (--) for single-line or nested comments. Comments inserted with -- are terminated by the newline character."
That seems to me to suggest that -- comments can be nested (although I know the can't). Yes, it says the comment text isn't parsed. However, the /* page also says that the comment text isn't parsed (" The text between the /* and */ is not evaluated by the server.") although it does go on to blatantly contradict itself further down the page. You may think that that is clear and simple documentation that documents the fact that -- trumps \*. I don't.
Tom
September 25, 2013 at 7:13 am
Interesting and easy question.
The answer is only true because "--" creates comments only for the same line.
The explanation is lacking in not pointing out the differences between using "--" and "/* */" that make the answer correct.
September 25, 2013 at 1:35 pm
Nice and easy - thanks, Samith!
September 25, 2013 at 11:51 pm
Samith, discover more fun of combining block comments and in-line comments ... my basic rule, to avoid the error your example raises, always put an inline comment just in front of the block close, like so.
--*/
http://www.sqlservercentral.com/articles/T-SQL/100061/
Try changing the value of @debug from '--' to '' in the following code:
declare @debug varchar(2) = '--'
declare @var varchar(1000)
set @var = @debug + '/*
select ''Samith'' name --*/'
set @var = @var + ' select ''sas'''
exec (@var)
cheers,
zerko
September 26, 2013 at 6:58 am
Good one, thanks!
September 26, 2013 at 4:11 pm
EZ PZ
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
September 28, 2013 at 6:38 am
Toreador (9/24/2013)
I got this wrong because I assumed the "*/" was only on a new line because it had been wrapped by the narrow display 🙁
+1
October 11, 2013 at 5:33 am
pchirags (9/28/2013)
Toreador (9/24/2013)
I got this wrong because I assumed the "*/" was only on a new line because it had been wrapped by the narrow display 🙁+1
same for me
Viewing 8 posts - 31 through 37 (of 37 total)
You must be logged in to reply to this topic. Login to reply