having worked with a 4-5-4 calendar in the past, i can tell you with complete honesty that the easiest way to proceed is with a
calendar table
basically, generate a row for every date, with the date as the primary key, and as many data columns as you can think of that will prove useful, e.g. Year, Month, Day, dayofweek, isStatHoliday, calendarWeekno, fiscalWeekno, fiscalQuarter, etc.
then join the calendar table to your data on date, and GROUP BY the calendar column, e.g. fiscalWeekno
this method will require zero maintenance when converting to a different SQL language, whereas date functions typically require tweaking
4-5-4 fiscal periods are hell to calculate on the fly, and writing a user-defined function is needlessly complex
r937.com |
rudy.ca