|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 8:47 AM
Points: 304,
Visits: 552
|
|
|
|
|
|
SSC-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'
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 9:27 AM
Points: 1,538,
Visits: 802
|
|
Nice question.
What a counterintuitive way this behaves!
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 12:01 PM
Points: 2,677,
Visits: 2,273
|
|
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
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 5:13 AM
Points: 1,123,
Visits: 986
|
|
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).
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Yesterday @ 1:35 AM
Points: 329,
Visits: 186
|
|
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.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 12:01 PM
Points: 2,677,
Visits: 2,273
|
|
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
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 9:27 AM
Points: 1,538,
Visits: 802
|
|
| 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.
|
|
|
|
|
SSC-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
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 12:01 PM
Points: 2,677,
Visits: 2,273
|
|
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
|
|
|
|