New Year's Math

  • Comments posted to this topic are about the item New Year's Math

  • Nice one...nothing complex.. need to read the Qstn with patience...



    Desire to learn new things..

  • Thanks for the question.

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

  • Yes, Patience is the key..

    nice question.. too much to read though. 🙂

    ~ demonfox
    Wondering what I would do next , when I am done with this one :ermm:

  • This was removed by the editor as SPAM

  • Nice question Thanks. 🙂

  • Nice question and great explanation - didn't know about the literals in the declaration, so thanks for that too.

  • I got it right because although I couldn't be bothered working through the code, it was clearly adding lots of things to @NewYearsEve so the answer was never going to be either @NewYearsEve or @NewYearsDay. As there was no syntax error, that left only one possibility 🙂

  • I got this one fine as I have done lots of date time manipulation in SQL and other languages, but I'll happily admit the explanation put an interesting new (for me) perspective on the DATEADD and DATEDIFF functions. Nice one, cheers.

  • Thanks for the question.

  • Good topic for a question. However since I always try to get the answer without running the code I tend to really dislike questions with this level of nested logic. I am horrible at being a sql engine but pretty decent at deciphering code. I was unable to keep focus long enough to decipher the overly complicated query. I think you could have presented the idea with a far less complicated query.

    That being said the explanation was good and it is always good to have a refresher on how these functions work. Thanks for the question.


    Need help? Help us help you.

    Read the article at for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns -
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs -
    Understanding and Using APPLY (Part 1) -
    Understanding and Using APPLY (Part 2) -

  • I solved it like Toreador, but at the same time I found the explanation about the literals interesting.

    thanks for the question!

    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

  • Interesting question -- I figured out the date math but had to find what that ODBC syntax was about. There is always something new or so far unexplored to learn. Thanks!

  • Nice question. I enjoyed it.

    The "flying duck" code layout made it easy to check that the parentheses matched up, so could see easily that there was no syntax error unless it was caused by those strange literals. So I had to find out what those strange literals were before going any further. First I hit on Date, Time, and Timestamp Literals but the nasty typo on that page ("-type" for "literal-type") confused me so I looked further and found Date, Time, and Timestamp Escape Sequences which gave me what I needed (and showed clearly that my confusion with the earlier page was due to a typo) so now I knew there wasn't a syntax error.

    So then I could follow a process much like what some others have mentioned. Since a lot of things were added, all integer multiples of one second and none of them zero, the miliseconds in the result had to be the same as in the starting point (non-zero) and the resulting datetime had to be greater than the starting point - so only one of the options fitted the bill. No need to do any arithmetic - but it made me think!


  • Very interesting question. But a lot of reading 😀

    Need an answer? No, you need a question
    My blog at
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 15 posts - 1 through 15 (of 15 total)

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