Dynamic Query

  • Toreador

    SSChampion

    Points: 11256

    I got this wrong because I assumed the "*/" was only on a new line because it had been wrapped by the narrow display πŸ™

  • Dscheypie

    SSCommitted

    Points: 1545

    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.

  • Dscheypie

    SSCommitted

    Points: 1545

    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.

  • Samith C

    Mr or Mrs. 500

    Points: 519

    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]

  • Ed Wagner

    SSC Guru

    Points: 286982

    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.

  • paul.knibbs

    SSCoach

    Points: 15270

    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!

  • Mike Dougherty-384281

    SSCrazy

    Points: 2764

    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*

  • Samith C

    Mr or Mrs. 500

    Points: 519

    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]

  • Dana Medley

    SSCertifiable

    Points: 6764

    Thanks for the great question



    Everything is awesome!

  • Hugo Kornelis

    SSC Guru

    Points: 64685

    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'


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • sknox

    SSChampion

    Points: 12292

    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.

  • sknox

    SSChampion

    Points: 12292

    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. πŸ˜›

  • TomThomson

    SSC Guru

    Points: 104773

    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

  • Narud

    SSCrazy

    Points: 2826

    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

  • Hugo Kornelis

    SSC Guru

    Points: 64685

    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.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

Viewing 15 posts - 16 through 30 (of 38 total)

You must be logged in to reply to this topic. Login to reply