I have a table activities of activity entries, e.g.:
ID | Date | Activity | Participant
---+------------+----------+
1 | 11/30/2011 | Skiing | Alice
2 | 11/29/2011 | Diving | Gary
3 | 10/15/2011 | Running | Therese
and I’d like to query, for a given date range, which days had an activity and which ones didn’t have anything, for every participant, e.g., for 11/29-11/30,
Date | Activity | Participant
------+-----------+------------
11/29 | | Alice
11/30 | Skiing | Alice
11/29 | Diving | Gary
11/30 | | Gary
11/29 | | Therese
11/30 | | Therese
My current plan is to make a table allDates of all the dates in the year, take a Cartesian product query cartDateParticipant:
select date,participant from allDates,(select distinct participant from activities) as participants
and left join that query against activities:
select a.date, c.activity, c.participant from allDates a
left join
cartDateParticipant c
on
a.date=c.date
and
a.participant=c.participant
which will work, but that means I have to keep a table of dates for any possible date range entered by the user. Is there any way to generate a sequence of dates on the fly in Access without having to store it as a table? Or is there a better way to write this query?
EDIT: The client finally relented and decided that the blank rows were unnecessary, so I just wrote it as a standard query.
I’ll venture an answer since nobody else has. Creating a table of dates is not perhaps particularly cool or clever. However, it is simple to understand, and therefore straightforward to implement and to maintain. I would stick with that method, and say, “no, there’s no better way to write the query” using MS Access.