• kl25 (11/30/2012)


    To follow-up my earlier suggestion, note that Cadavre's approach uses a tally table. A calendar table is a specialized version of a tally table.

    In fact, my CTE tally table is a calendar table (note: TALLY(N) AS (SELECT DATEADD(month, N, 0) FROM CTE6) ) of months starting at 1900-01-01 and ending with 9999-12-01 (total is 97,200 rows, so I probably went overboard with the CTEs that build the sequential number lists 😛 )


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/