• Mikael Eriksson SE (1/16/2014)


    There is one more thing to notice about the first query.

    You assign the value "2000-02-01 12:34:56.789" to @EndDT but the query returns "2000-01-02 12:34:56.789".

    Either make sure you are using "SET DATEFORMAT YMD" or use an unambiguous date format for the string literal "2000-02-01T12:34:56.789".

    Thanks for the heads up, Mikael... it wasn't all that about unambiguous dates (which is whatI used)... it was a phat phinger during transfer of the code to the article submission site. I've submitted a correction that they'll, hopefully, be able to get to right away.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)