Will Terminators Be Required?

  • Lynn Pettis - Monday, August 6, 2018 10:45 AM

    Actually, the MERGE statement is required to be terminated by a semicolon.
    Not sure about any other new stuff.

    Ah... okay I was mostly thinking of CTE's I don't use merge enough to notice.

  • I do not like punctuation it is too small to look significant and easily missed.
    I have convinced myself (maybe wrongly) that a semicolon is not a statement terminator but a statement delimiter. That way I can quite happily add a semicolon at the front of a WITH line and not feel guilty.

    I can see why Microsoft enforced this as you can have a select with a WITH statement for table hints
    SELECT * FROM myTable
    [ WITH ( < table_hint > [ [ , ]...n ] ) ] 

    Or you could have two statements where the WITH is the start of the CTE:
    SELECT * FROM myTable;
    [ WITH <common_table_expression> [ ,...n ] ]

  • Jonathan AC Roberts - Monday, August 6, 2018 11:59 AM

    I do not like punctuation it is too small to look significant and easily missed.
    I have convinced myself (maybe wrongly) that a semicolon is not a statement terminator but a statement delimiter. That way I can quite happily add a semicolon at the front of a WITH line and not feel guilty.

    I can see why Microsoft enforced this as you can have a select with a WITH statement for table hints
    SELECT * FROM myTable
    [ WITH ( < table_hint > [ [ , ]...n ] ) ] 

    Or you could have two statements where the WITH is the start of the CTE:
    SELECT * FROM myTable;
    [ WITH <common_table_expression> [ ,...n ] ]

    Putting the semicolon at the beginning of a CTE is my biggest pet peeve.  You may call it a separator but it is a terminator.  With your logic that also means you are happy with a semicolon in front of the THROW statement as it also requires the previous statement be terminated with a semicolon.

  • Lynn Pettis - Monday, August 6, 2018 1:04 PM

    Putting the semicolon at the beginning of a CTE is my biggest pet peeve.  You may call it a separator but it is a terminator.  With your logic that also means you are happy with a semicolon in front of the THROW statement as it also requires the previous statement be terminated with a semicolon.

    I also think of semicolons more as delimiters.  I tend to put my semicolons on separate lines, mostly for ease of editing, but because they also stand out more when they are the only printable character on a line.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Lynn Pettis - Monday, August 6, 2018 1:04 PM

    Putting the semicolon at the beginning of a CTE is my biggest pet peeve.  You may call it a separator but it is a terminator.  With your logic that also means you are happy with a semicolon in front of the THROW statement as it also requires the previous statement be terminated with a semicolon.

    That's odd because I'm not happy with a semicolon at the beginning of a throw. I've been putting the semicolon in the statement before the throw not at the front of the throw. Normally (in my code anyway) the throw is inside a catch block so I've somehow also convinced myself that I should punctuate the inside a catch block.

Viewing 5 posts - 31 through 34 (of 34 total)

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