Are we in all these cities?

  • I totally missed that spurious semicolon in the subquery.

    I was focused on the logic of the statement, and not a spurious typo.

    This question TOTALLY FAILS to illustrate any point about a correlated subquery. The only point this question illustrates is that I was not careful enough in my review of the statement, and that including an invalid token in a SQL statement is a syntax error.

    I could get the exact same result with a misspelled a keyword.

  • I totally missed that spurious semicolon in the subquery.

    I was focused on the logic of the statement, and not a spurious typo.

    Good to hear someone put what I felt here into words.

    Jamie

  • Hugo Kornelis (7/13/2010)


    I hope the author will stop by and tell us what he/she was trying to teach us with this question. Maybe I missed the deeper issue here.

    I guess the deep issue here is that code-reading/checking is an important part of many jobs; most of us tend to skim read and not notice errors, so it's as well to be reminded now and again tha reading is important. I'm pretty lazy about this for my own code and it would be a crime if I fed my stuff into execution without getting the parser to do a syntax check first, but I have had to evaluate other people's code too so the occassional reminder that I should look more carefully is a good thing, because there is always the risk that if one is skimming so that syntax errors are missed maybe some errors of logic will be missed too because one is not reading carefully enough.

    Incidentally, I was unpleasantly surprised by the introduction of mandatory semicolons into what should be a nice clean syntax that can be parsed unambiguously without these markers. I wonder whether something has been added to the language that genuinely prevents detection of some statement boundaries without specific separators (that would be a pretty stupid thing to do, but I've seen stupider things happen) or was some parser development team just too lazy to do it right; and I'm sad to see that MS is planning to make unneeded separators mandatory at some point in the future.

    Tom

  • Tom.Thomson (7/26/2010)


    Incidentally, I was unpleasantly surprised by the introduction of mandatory semicolons into what should be a nice clean syntax that can be parsed unambiguously without these markers. I wonder whether something has been added to the language that genuinely prevents detection of some statement boundaries without specific separators (that would be a pretty stupid thing to do, but I've seen stupider things happen) or was some parser development team just too lazy to do it right; and I'm sad to see that MS is planning to make unneeded separators mandatory at some point in the future.

    As far as I know (and I'm too lazy to check right now), the semicolon has always been mandatory in ANSI SQL.

    I'm glad it will become mandatory. One of my worst nightmares was when a coworker was repairing bad data in a production environment. To make sure he got the WHERE clause perfect to find only the rows to be removed, he used this code:

    --DELETE FROM TheTable

    SELECT FROM TheTable

    WHERE (very complex clause)

    When he finally had the WHERE clause perfect, he uncommented the DELETE, then hit the EXECUTE button.

    This was the only time we were all glad that the triggers on this table were so painfully slow (they used row by row processing, in a very inefficient way to boot). After a few minutes, the phone started ringing because all users were blocked; we were able to kill the process before it finished. Which saved us a LOT of grief, since that database was in the simple recovery model.

    With a mandatory semicolon statement seperator, this mistake would simply have returned an error message.

    Also, while it may be possible to build a parser that does it job without needing semicolons, evenn Microsoft has limited resources - I'd rather see them spend those on new features rather than maintaining a parser that could be simplified by simply requiring semicolons.


    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/

  • Thanks for the question. I was ticked since I got it wrong, but it is too easy to just gloss over a script when reading it. A good reminder to be careful.

    -Dan

  • I thought ';' is a typo and ignored that.

  • DhruvShah (9/28/2010)


    I thought ';' is a typo and ignored that.

    LOL....

    Who uses a ';' anyway? it's not yet standard practice and if you do, you should realise that it would cause problems in the middle of a statement.

    I need to buy some glasses now... I thought the trick was with the subquery referencing the main table with an alias, which is more informative. Suppose, I need to buy some glasses now...

  • terrykzncs (4/22/2011)


    Who uses a ';' anyway? it's not yet standard practice and if you do, you should realise that it would cause problems in the middle of a statement.

    For starters anyone that has to use Oracle. (Since it is required.)

    Also, Microsoft has deprecated not using ; so in the next version or two of SQL Server you will probably be required to, so it might be a good idea to start now so you don't have to go back and add the ; to all of your code later.

    From http://msdn.microsoft.com/en-us/library/ms143729.aspx:

    Not ending Transact-SQL statements with a semicolon.

Viewing 8 posts - 46 through 52 (of 52 total)

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