In Ac97, I have a table Activity that has a date/time field. There can be multiple records on any day, or no records.
I'm trying to write a query to sum the records for each day so I can generate a report to show the totals for each day of the month, including 0's for days without any records.
Here is some sample data:
WeightDate Unit1 Unit2
10/21/07 6:00 AM 600 200
10/22/07 9:00 PM 300 100
10/23/07 5:00 AM 500 250
10/23/07 7:00 AM 700 800
10/25/07 5:00 AM 200 100
Note the multiple records for 10/23/07 and none for 10/24/07.
I would like the query to return:
WeightDate Unit1 Unit2
10/21/07 600 200
10/22/07 300 100
10/23/07 1200 1050
10/25/07 200 100
Note the sum for 10/23/07.
So that the report will show.
WeightDate Unit1 Unit2
10/21/07 600 200
10/22/07 300 100
10/23/07 1200 1050
10/24/07 0 0
10/25/07 200 100
Note the "0"s for 10/24/07 when there were no records for 10/24/07.
I tried the following query but it doesn't show the WeightDate in the result, it only shows the following.
Unit1 Unit2
600 200
300 100
1200 1050
200 100
How do I get the query to include the dates so I can show them in my report?
Thanks,
Brian
I'm trying to write a query to sum the records for each day so I can generate a report to show the totals for each day of the month, including 0's for days without any records.
Here is some sample data:
WeightDate Unit1 Unit2
10/21/07 6:00 AM 600 200
10/22/07 9:00 PM 300 100
10/23/07 5:00 AM 500 250
10/23/07 7:00 AM 700 800
10/25/07 5:00 AM 200 100
Note the multiple records for 10/23/07 and none for 10/24/07.
I would like the query to return:
WeightDate Unit1 Unit2
10/21/07 600 200
10/22/07 300 100
10/23/07 1200 1050
10/25/07 200 100
Note the sum for 10/23/07.
So that the report will show.
WeightDate Unit1 Unit2
10/21/07 600 200
10/22/07 300 100
10/23/07 1200 1050
10/24/07 0 0
10/25/07 200 100
Note the "0"s for 10/24/07 when there were no records for 10/24/07.
I tried the following query but it doesn't show the WeightDate in the result, it only shows the following.
Unit1 Unit2
600 200
300 100
1200 1050
200 100
Code:
SELECT Sum(nz([Unit1],0)) AS Total1, Sum(nz([Unit2],0)) AS Total2
FROM Activity
GROUP BY DateValue(WeightDate);
How do I get the query to include the dates so I can show them in my report?
Thanks,
Brian