September 24, 2013 at 2:04 am
I got this wrong because I assumed the "*/" was only on a new line because it had been wrapped by the narrow display π
September 24, 2013 at 3:12 am
Hoi, Samith,
how fits the explanation of your reference to our problem at hand?
The reference explains something about the parser of SSMS before the execution of the code and the block comment tag inside a string.
In my opinion your QotD refers to another problem: You have a line comment "--" outcommenting the beginning block comment.
So the block comment end tag has no beginning tag; _for me_ this is quite a different explanation. So what did I overlook?
Best regards
Jens-Peter π
________________________________________________________
If you set out to do something, something else must be done first.
September 24, 2013 at 3:13 am
Jamsheer (9/24/2013)
I LOVE TRICKY QUESTIONS ALWAYS... THANKS SAMITH..
Same for me, anyway...
________________________________________________________
If you set out to do something, something else must be done first.
September 24, 2013 at 6:06 am
Dscheypie (9/24/2013)
Hoi, Samith,how fits the explanation of your reference to our problem at hand?
The reference explains something about the parser of SSMS before the execution of the code and the block comment tag inside a string.
In my opinion your QotD refers to another problem: You have a line comment "--" outcommenting the beginning block comment.
So the block comment end tag has no beginning tag; _for me_ this is quite a different explanation. So what did I overlook?
Best regards
Jens-Peter π
The reason for the Error is which I told
and the link I provided to share an idea on Commented lines
[font="Verdana"] There is no Wrong time to do a Right thing π [/font]
September 24, 2013 at 7:03 am
It is a good reminder that no matter how simple or complicated anything gets, don't forget the basics. A comment is about as basic as you can get and closing comment blocks is important.
September 24, 2013 at 8:44 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 π
Similar here--my brain just sort of skipped over the newline without noticing it was there!
September 24, 2013 at 9:14 am
Why would anyone generate dynamic sql with comments in the to-be-executed string?!
These subtleties of line-commented block-comment and comments-with-comments defeats the whole purpose of comments: to clarify what should be already readable & well-written code.
"be careful of the load-bearing line comment" is not something I ever want to encounter. π
heh *harumph*
September 24, 2013 at 9:19 am
Mike Dougherty-384281 (9/24/2013)
Why would anyone generate dynamic sql with comments in the to-be-executed string?!These subtleties of line-commented block-comment and comments-with-comments defeats the whole purpose of comments: to clarify what should be already readable & well-written code.
"be careful of the load-bearing line comment" is not something I ever want to encounter. π
heh *harumph*
take it as a tricky question dude ..
We all aware of the same π
[font="Verdana"] There is no Wrong time to do a Right thing π [/font]
September 24, 2013 at 12:17 pm
Thanks for the great question
September 24, 2013 at 12:40 pm
So why does the question use dynamic SQL? If the focus is on how different kinds of comments relate, why not simply use:
-- /* select 'Samith' name
*/ select 'sas'
September 24, 2013 at 1:52 pm
Mike Dougherty-384281 (9/24/2013)
...These subtleties of line-commented block-comment and comments-with-comments defeats the whole purpose of comments: to clarify what should be already readable & well-written code.
...
Clarification is not the entire purpose of comments.
Comments are often used to turn on/off sections of code during testing.
Sometimes code even has to go into production with one section disabled due to factors beyond the developer's control. It can be simpler to leave the bit in but commented out, and just uncomment the desired code once the external issues have been resolved.
September 24, 2013 at 1:56 pm
Hugo Kornelis (9/24/2013)
So why does the question use dynamic SQL? If the focus is on how different kinds of comments relate, why not simply use:
-- /* select 'Samith' name
*/ select 'sas'
Your example explains itself -- look at the syntax highlighting. It's not much of a question if the example tells you the answer -- unless you just want to test ability to interpret the highlighting. π
September 24, 2013 at 3:23 pm
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?
Tom
September 24, 2013 at 4:09 pm
Hany Helmy (9/24/2013)
Although I was pretty sure that this is another tricky question and my answer will be wrong when I pressed Submit button; but surprisingly it was correct πexec @variable; hmmm always good to refresh the mind with hidden & forgotten basics.
+1
September 24, 2013 at 4:11 pm
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.
Viewing 15 posts - 16 through 30 (of 37 total)
You must be logged in to reply to this topic. Login to reply