• A calendar table is not really needed for this:

    select

    YearMonth = dateadd(mm,datediff(mm,0,[recorddate]),0),

    MyValueSum = sum([myvalue])

    from

    #a

    group by

    dateadd(mm,datediff(mm,0,[recorddate]),0)

    order by

    dateadd(mm,datediff(mm,0,[recorddate]),0)

    Results:

    YearMonth MyValueSum

    ----------------------- -----------

    2012-01-01 00:00:00.000 30

    2012-02-01 00:00:00.000 70

    2012-08-01 00:00:00.000 50

    2012-12-01 00:00:00.000 130