Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

Complicated Comments Expand / Collapse
Author
Message
Posted Tuesday, February 10, 2009 9:25 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, May 15, 2014 12:28 PM
Points: 305, Visits: 565
Comments posted to this topic are about the item Complicated Comments

Jesse McLain
jesse@jessemclain.com
www.jessemclain.com
www.jessesql.blogspot.com
Post #654391
Posted Wednesday, February 11, 2009 2:21 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, August 25, 2009 1:13 AM
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'
Post #654550
Posted Wednesday, February 11, 2009 2:24 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, June 30, 2014 2:30 AM
Points: 1,614, Visits: 890
Nice question.

What a counterintuitive way this behaves!
Post #654552
Posted Wednesday, February 11, 2009 2:44 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 8:34 AM
Points: 2,684, Visits: 2,432
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
Post #654565
Posted Wednesday, February 11, 2009 2:44 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, July 9, 2014 2:52 AM
Points: 1,153, Visits: 1,047
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).

Post #654566
Posted Wednesday, February 11, 2009 2:46 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 1:49 AM
Points: 359, Visits: 225
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.
Post #654569
Posted Wednesday, February 11, 2009 2:51 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 8:34 AM
Points: 2,684, Visits: 2,432
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
Post #654573
Posted Wednesday, February 11, 2009 2:56 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, June 30, 2014 2:30 AM
Points: 1,614, Visits: 890
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.
Post #654578
Posted Wednesday, February 11, 2009 3:02 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, August 25, 2009 1:13 AM
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

This question gives me a better understanding of my past though
Post #654585
Posted Wednesday, February 11, 2009 4:36 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 8:34 AM
Points: 2,684, Visits: 2,432
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
Post #654647
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse