Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Complicated Comments


Complicated Comments

Author
Message
Jesse McLain
Jesse McLain
Old Hand
Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)Old Hand (307 reputation)

Group: General Forum Members
Points: 307 Visits: 567
Comments posted to this topic are about the item Complicated Comments

Jesse McLain
jesse@jessemclain.com
www.jessemclain.com
www.jessesql.blogspot.com
Philippe Lauwers
Philippe Lauwers
SSC-Enthusiastic
SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)

Group: General Forum Members
Points: 100 Visits: 26
I could hardly believe I got it wrong, so I tried it in DbVisualiser ... I got 1,4,5,7,8 (just as I thought I would). Could this have something to do with using DbVisualiser (I guess not, since SQL is executed on the server anyway)?

My interpretation is as follows:

This opens a block comment... /*
...so this is not printed PRINT '6'
This is ignored since it is part of the block comment --/*
and it is not the closing of the block comment
This closes the block comment... */
...thanks to which this is printed PRINT '7'
This is an inline comment so it does nothing --*/
This is printed PRINT '8'
Rachel Byford
Rachel Byford
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1620 Visits: 952
Nice question.

What a counterintuitive way this behaves!
kevriley
kevriley
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2751 Visits: 2606
Philippe Lauwers (2/11/2009)
I could hardly believe I got it wrong, so I tried it in DbVisualiser ... I got 1,4,5,7,8 (just as I thought I would). Could this have something to do with using DbVisualiser (I guess not, since SQL is executed on the server anyway)?

My interpretation is as follows:

This opens a block comment... /*
...so this is not printed PRINT '6'
This is ignored since it is part of the block comment --/*
and it is not the closing of the block comment
This closes the block comment... */
...thanks to which this is printed PRINT '7'
This is an inline comment so it does nothing --*/
This is printed PRINT '8'



Philippe, can you try this in Query Analyzer/SSMS (whichever version you have) and see if you get a different answer (which you will) - then I guess it is something to do with DbVisualiser !??!?




Kev
archie flockhart
archie flockhart
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1253 Visits: 1150
Got it wrong , read the answer/explanation, didn't really believe it, so tried it in Query Analyser which gave the answer stated as the solution. But I still don't understand why ...

My step-by-step interpretation was the same as Phillipe's. And Query Analyser's own code-formatting algorithm takes the same view:the PRINT statements for 1,4,5,7 and 8 appear dark blue ( non-commented) while the statements for 2,3 and 6 appear light blue (commented).
Russ Derrett
Russ Derrett
Old Hand
Old Hand (390 reputation)Old Hand (390 reputation)Old Hand (390 reputation)Old Hand (390 reputation)Old Hand (390 reputation)Old Hand (390 reputation)Old Hand (390 reputation)Old Hand (390 reputation)

Group: General Forum Members
Points: 390 Visits: 270
This is a new bit of information to me.

I would have agreed with Phillippe's logic and so would have expected the 7 to show, but when I ran it in Management Studio you are correct. I didn't realise you could nest comments like this.

Thanks for a great question and increasing my obviously limited knowledge.
kevriley
kevriley
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2751 Visits: 2606
archie flockhart (2/11/2009)
Got it wrong , read the answer/explanation, didn't really believe it, so tried it in Query Analyser which gave the answer stated as the solution. But I still don't understand why ...

My step-by-step interpretation was the same as Phillipe's. And Query Analyser's own code-formatting algorithm takes the same view:the PRINT statements for 1,4,5,7 and 8 appear dark blue ( non-commented) while the statements for 2,3 and 6 appear light blue (commented).



Archie - can you try in SSMS? I get a different code-formatting, which shows it coloured as it works.

BTW - I'm on SSMS 9.00.3042.00 i.e. 2005 SP2


Kev
Rachel Byford
Rachel Byford
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1620 Visits: 952
In SQL 2000 Query Analyzer it formats the text as if PRINT '7' will happen, and yet it doesn't when you execute it. They must have updated things a bit in SSMS.
Philippe Lauwers
Philippe Lauwers
SSC-Enthusiastic
SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)

Group: General Forum Members
Points: 100 Visits: 26
kevriley (2/11/2009)


Philippe, can you try this in Query Analyzer/SSMS (whichever version you have) and see if you get a different answer (which you will) - then I guess it is something to do with DbVisualiser !??!?

Kev


Sorry, I would love to but company policy ... DbVisualiser is the only tool I've got Angry

This question gives me a better understanding of my past though Crazy
kevriley
kevriley
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2751 Visits: 2606
Rachel Byford (2/11/2009)
In SQL 2000 Query Analyzer it formats the text as if PRINT '7' will happen, and yet it doesn't when you execute it. They must have updated things a bit in SSMS.



Thanks Rachel - I didn't have a version of 2000 I could lay my hands on to quickly check.....


Kev
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search