• Eirikur Eiriksson (9/13/2014)


    Jeff Moden (9/12/2014)


    The following should do it (see attached). I made sure that it's a high performance iTVF instead of an mTVF. I also got rid of the resource hungry, performance robbing recursive CTE that counts and added a column to return the number of days in each week. Of course, you can remove that column if you'd prefer it not to be there.

    Nice one Jeff, is there a spackle coming?

    😎

    Thanks, Eirikur, especially for the idea of Spackling this. I suppose I could expand on it a bit to include multiple months to make it more useful. Actually, come to think of it and except for a modernization of technique, it's mostly written from a post I did on another site back in 2007. Add a week number to each row and it's mostly done.

    https://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1173&lngWId=5

    --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)