Hi Lochness,
Here are the steps required to create the necessary query in Microsoft
Access 2000:
1/ Click on queries from the Access main menu and select "Create Query
in Design view".
2/ On the listbox that appears, select the table which you have
described in your question. Then click "Close"
3/ Select the fields you wish to query, in your example you would
double click on "Date" and "Activ". Beware using the word "Date" as a
field name as in your example, Access will try and interpret the word
"date" as todays actual date. If you have to specify "date" in the
query directly, you must enclose it in square brackets "[]".
4/ Look in the toolbar for the "Sum" icon. It looks like a black "E"
and should be next to the combo-box in the toolbar. If you cant see
the Toolbar select "View>Toolbars>Query Design". Notice that when this
icon is select the words "Group By" appear next to total in the table.
5/ In the column for "Activ" select the word "Count" instead of "Group
By". Next to date, set "Sort" to "Descending" to provide your results
to ASP in chronological order.
You can test your query by clicking the exclamation mark "!" in the
toolbar.
The SQL for this query will look like this (assuming your table name
is "Activities":
SELECT Activities.[Date], Count(Activities.Activ) AS CountOfActiv
FROM Activities
GROUP BY Activities.[Date]
ORDER BY Activities.[Date] DESC;
You can copy and paste this text into Access SQL query design if you
wish.
This will satisfy your requirements EXCEPT for the date showing with 0
activities in the ASP report.
The reason for this is that Access has no real concept of consecutive
dates, It does not know to report 2/AUG/2002 between 1/AUG/2002 and
3/AUG/2002, it will only report for dates that actually exist in your
activities table, there are 2 main ways around this problem.
1/ Create a table that contains all the dates that you will be
reporting on. Join the table to the Activities table with a LEFT join
and select the "Date" field from the second table when perforing your
query.
2/ Make the report generator or front end ASP code generate the report
line by line for each date.
Neither of these solutions are elegant unfortuantely, I have always
gone with the first option.
Good luck,
Molloch-ga |