My table looks like this:Media----------mediaNo inttitle nvarchar(100)mediaDate smalldatetimemediaFile nvarchar(150)
And I want to display a summary of media appearances for a given month, and display it like:Janurary 2002 (12)December 2001 (17)November 2001 (4)
I have the following query, but it's not giving me the right solution: SELECT DateName(month, D.dates) + ' ' + DateName(year, D.Dates) MonthName,Count(*) mediaFROM media m INNER JOIN (SELECT mediaDate dates FROM media) DON m.mediaDate=D.datesGROUP BY DatePart(mm, D.Dates), DatePart(yy, D.Dates), DateName(month, D.dates) + ' ' + DateName(year, D.Dates)ORDER BY DatePart(yy, D.Dates) DESC, DatePart(mm, D.Dates) DESC
The problem is that it's giving me the total of all months for the first result, so the above data would look like this: Janurary 2002 (33)December 2001 (17)November 2001 (4)
Note that Janurary is 33, not 12. Any ideas?