• Geoff A (11/15/2010)


    Kristian Ask (11/15/2010)


    hugo-939487 (11/15/2010)


    Another variaton, using the MONTH function:

    SELECT [Month] = DATENAME(mm,SomeDateTime),

    Amount = SUM(SomeAmount)

    FROM #MyHead

    WHERE SomeDateTime >= '2010' AND SomeDateTime < '2011'

    GROUP BY DATENAME(mm,SomeDateTime), MONTH(SomeDateTime)

    ORDER BY MONTH(SomeDateTime)

    ;

    This is the best one, I think. Adding MONTH function won't change the grouping as it's the same and it will still use seek. You can also use DATEPART(mm, SomeDate).

    it really isn't the best one. when you compare Jeff's ORDER BY clause vs the one above, Jeff's is more efficient.

    I had to test to confirm because I assumed the CAST would cost more, but it doesn't.....

    You're quite right!