Grouping Data By Calendar Quarter

Comments

In creating a new report I needed a SQL View for an Access report on quarterly results.  The resulting code is actually quite simple, and because I use a view the report is very quick on a large set of data.

SELECT     TOP (100) PERCENT COUNT(TrackNum) AS Tracks, YEAR(StatusDate) AS year, { fn QUARTER(StatusDate) } AS quarter, StatusCode
FROM         dbo.StatusHistory
GROUP BY YEAR(StatusDate), { fn QUARTER(StatusDate) }, StatusCode
ORDER BY year, quarter, StatusCode

This gives me grouped results by quarter, showing total projects for each status.  Note that a Group By does usually bring a sort inherintly with it.  I have found this to be inconsistent and therefore add the Order By as well to ensure my resulting data is sorted properly.

Related Posts

Access 2016 Relationships

Short blog today, this is a great read on relationships in Access 2016: Access 2016 Relationships Thanks to Microsoft for this one!

Microsoft Access Union Query from Hell. Skill Level: Demi-God

The worst query I ever had to write which powers a master report for the database user.  Here it is.  I don't think I can make it smaller, there were too many weird rules, aggregates, and translations in it.  And we needed to pull different columns based on criteria. ...

0 Comments

0 Comments