J
John
Hello.
I'm having a bit of a problem with a query. First of all, let me just
emphasize that the final result of the query I want to build would be
relatively simple to create using VBA and a temporary table, but one of
the reasons I'm working on this database is that the old version has
temporary tables all over the place, so it's very messy and much larger
than it needs to be.
Anyway, here's what I want to do:
I have a form with two datepicker controls - one do pick a start date,
and one to pick an end date, so that I end up with a date range. I then
have a query that reads these two dates and returns a bunch of records
that fall within the chosen range, and summarizes them by month. The
challenge I'm having is that if there is no data for a month within the
range, then the query does not show that month. I want it to show the
month, with all the summary fields showing zeros. For example, if I
chose Jan 2008 to Mar 2008, but there was no data for Feb 2008, I want
it to show this:
January 2008 516 72 9
February 2008 0 0 0
March 2008 834 291 34
But what it's showing is this:
January 2008 516 72 9
March 2008 834 291 34
Using a temporary table, I could loop through the months between Jan and
Mar, adding them to the table, and then use that table to do a left join
on my actual data queries. This would ensure that all the months are
listed, but it would create some junk data within the database. Also, it
could cause problems if multiple users tried to run the same report
(with different parameters) at the same time. So, I'd like to accomplish
this in a query, or a combination of queries. E.g. if I had a query that
listed all dates between two given dates, I could create another query
based on that one to reduce the dates to months and years.
Any thoughts?
Thanks,
John
I'm having a bit of a problem with a query. First of all, let me just
emphasize that the final result of the query I want to build would be
relatively simple to create using VBA and a temporary table, but one of
the reasons I'm working on this database is that the old version has
temporary tables all over the place, so it's very messy and much larger
than it needs to be.
Anyway, here's what I want to do:
I have a form with two datepicker controls - one do pick a start date,
and one to pick an end date, so that I end up with a date range. I then
have a query that reads these two dates and returns a bunch of records
that fall within the chosen range, and summarizes them by month. The
challenge I'm having is that if there is no data for a month within the
range, then the query does not show that month. I want it to show the
month, with all the summary fields showing zeros. For example, if I
chose Jan 2008 to Mar 2008, but there was no data for Feb 2008, I want
it to show this:
January 2008 516 72 9
February 2008 0 0 0
March 2008 834 291 34
But what it's showing is this:
January 2008 516 72 9
March 2008 834 291 34
Using a temporary table, I could loop through the months between Jan and
Mar, adding them to the table, and then use that table to do a left join
on my actual data queries. This would ensure that all the months are
listed, but it would create some junk data within the database. Also, it
could cause problems if multiple users tried to run the same report
(with different parameters) at the same time. So, I'd like to accomplish
this in a query, or a combination of queries. E.g. if I had a query that
listed all dates between two given dates, I could create another query
based on that one to reduce the dates to months and years.
Any thoughts?
Thanks,
John