DateTime Precision

  • tks all for the commentary today too! 🙂

  • Thanks for the ¿

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Interesting question. Thanks!

  • Hugo Kornelis (11/28/2011)


    roger.plowman (11/28/2011)


    Using single quotes for both strings and dates is a brain-dead design decision--period.

    Technically, T-SQL is not using single quotes for both strings and dates. It uses single quotes for strings only.

    There is no way to have date literals in T-SQL; that's why we have to make do with string literals that will be converted (at execution time) to date or datetime values.

    </pedantic>

    Single quotes ARE for strings only, true. So the trouble comes from our getting used to implicit conversions and expecting them based on our human experience. As may have been noticed in the past, MS SQL is not human 😉 . We either have to remind ourselves to consider datatypes (as so many QODs do), or look for MS to require explicit conversion, either with a CAST/CONVERT or special delimiters as with the suggested pound-sign notation #2011-11-28#. If I'm voting, I say leave it as is and stay alert.

  • Guilty as charged. I fell for this in a production environment. It was a particularly difficult bug to find. I Did not recognize it was doing the implicit conversion as strings.

    Cheers, J

  • good question!


    [font="Times New Roman"]rfr.ferrari[/font]
    DBA - SQL Server 2008
    MCITP | MCTS

    remember is live or suffer twice!
    the period you fastest growing is the most difficult period of your life!
  • Ouch, you got me, I assumed implicit conversion without thinking it through. Thanks for the question.

    /@devandreas

  • 1+ for me

    Neeraj Prasad Sharma
    Sql Server Tutorials

Viewing 8 posts - 31 through 37 (of 37 total)

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