Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to GROUP BY Months?

Status
Not open for further replies.

PTW

Programmer
Jul 7, 2000
82
CA
I'm trying to get counts of records grouped by month. Each record has a date field. Is there a way that I can manipulate the DateTime functions to get the records counted and grouped not only by month, but in correct month order? I can only seem to do a grouping on an original field (the date field), and not on a portion of the field. Thanks!
 
[tt]select DatePart(mm, MyDateColumn), count(*)
from MyTable
group by DatePart(mm, MyDateColumn)
order by 1 [/tt] Robert Bradley
teaser.jpg

 
Just a note, if the report spans more than one year you will want to group by datepart(yy,mydatecolumn) also.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top