New Year's Math

  • sknox

    SSChampion

    Points: 12243

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

  • Dineshbabu

    Hall of Fame

    Points: 3220

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

    --

    Dineshbabu

    --
    Dineshbabu
    Desire to learn new things..

  • SQLRNNR

    SSC Guru

    Points: 281205

    Thanks for the question.

    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

  • demonfox

    SSCertifiable

    Points: 6289

    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

  • louigopal

    Mr or Mrs. 500

    Points: 575

    Nice question Thanks. 🙂

  • Michael Riemer

    SSCarpal Tunnel

    Points: 4947

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

  • Toreador

    SSChampion

    Points: 11243

    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 🙂

  • call.copse

    SSCoach

    Points: 16922

    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.

  • (Bob Brown)

    SSCrazy

    Points: 2705

    Thanks for the question.

  • Sean Lange

    SSC Guru

    Points: 286486

    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 http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • mtassin

    SSC-Insane

    Points: 23096

    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]

  • Revenant

    SSC-Forever

    Points: 42467

    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!

  • TomThomson

    SSC Guru

    Points: 104772

    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!

    Tom

  • Koen Verbeeck

    SSC Guru

    Points: 258955

    Very interesting question. But a lot of reading 😀

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

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

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