I'm not sure I completely understand your requirement, but I'll guess.
The trick here is to make another table that is a calendar containing just dates. This sort of table is very useful. You can add indicators to the rows in this table to indicate holidays and other non-business days if you want; then you can use the indicator in a WHERE clause to restrict the dates to just non-holidays, for example. But we'll assume a table that has just the following:
Code:
CREATE TABLE Calendar (
CalendarDate datetime NOT NULL PRIMARY KEY
);
You can populate this any number of ways; spreadsheets have functions which will generate dates easily and they are easy to import. You could also write a stored procedure (if you weren't using Access :)) to generate the dates to INSERT. In any case, this is only something you have to do every few years or so.
Once you have the calendar table, you just CROSS JOIN it to your input table, selecting only the dates in question, group by Department and Date and count them:
Code:
SELECT Department, Count(*) as DeptCount, CalendarDate
FROM yourtable CROSS JOIN Calendar
WHERE CalendarDate BETWEEN DateFrom AND DateTo
GROUP BY Department, CalendarDate
ORDER BY Department, CalendarDate;
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com