R
RussCRM
I work for a small homeless shelter. I have a table called
"Services"
that contains records with a ServiceID, GuestID, ServiceDate, and
ServiceType. Such as:
ServiceID (key) GuestID ServicesDate ServicesType
1875 4572 02/01/08 Men's Dorm
1877 9762 02/02/08 Men's Dorm
1892 9762 02/03/08 Men's Dorm
We also have a table called "Guest" with each guest's name and other
information.
For various reasons, we keep an ongoing count of how many nights in a
row a guest has stayed.
To count the total number of nights for a guest, we usually do a
dcount type of thing on ServiceID.
Anyone have any ideas how I could get a count of the number of days
in
a row a guest has stayed?
I have these two queries as suggested:
Query 1:qryCountPrep
SELECT a.ServicesType, a.ServicesID, a.ServicesLink, a.ServicesDate,
COUNT(*) AS Rank
FROM Services AS a INNER JOIN Services AS b ON
(a.ServicesDate>=b.ServicesDate) AND (a.ServicesLink=b.ServicesLink)
GROUP BY a.ServicesType, a.ServicesID, a.ServicesLink, a.ServicesDate;
Query 2:qryCount
SELECT a.ServicesID, Min(a.ServicesDate) AS StartDate,
Max(a.ServicesDate) AS LastDate, Max(a.ServicesDate)-
Min(a.ServicesDate)+1 AS NumberOfDays
FROM qryConsecutiveDateCountPrep2 AS a
WHERE ServicesType="Men's Dorm"
GROUP BY a.ServicesID, a.ServicesDate-a.Rank;
When I run them, I get a count of the number of days between the date
the guest first stayed and the last date the guest stayed. So, if a
guy stayed on February 1st for the first time and again on the 16th,
17th, and 18th. I would get "18" as the total number of days. But, I
want the total number of consecutive days prior to today. So, in this
case, I would be looking for "3" (assuming today is the 19th).
If this isn't possible, how would I at least get the number of stays
for the current month.
"Services"
that contains records with a ServiceID, GuestID, ServiceDate, and
ServiceType. Such as:
ServiceID (key) GuestID ServicesDate ServicesType
1875 4572 02/01/08 Men's Dorm
1877 9762 02/02/08 Men's Dorm
1892 9762 02/03/08 Men's Dorm
We also have a table called "Guest" with each guest's name and other
information.
For various reasons, we keep an ongoing count of how many nights in a
row a guest has stayed.
To count the total number of nights for a guest, we usually do a
dcount type of thing on ServiceID.
Anyone have any ideas how I could get a count of the number of days
in
a row a guest has stayed?
I have these two queries as suggested:
Query 1:qryCountPrep
SELECT a.ServicesType, a.ServicesID, a.ServicesLink, a.ServicesDate,
COUNT(*) AS Rank
FROM Services AS a INNER JOIN Services AS b ON
(a.ServicesDate>=b.ServicesDate) AND (a.ServicesLink=b.ServicesLink)
GROUP BY a.ServicesType, a.ServicesID, a.ServicesLink, a.ServicesDate;
Query 2:qryCount
SELECT a.ServicesID, Min(a.ServicesDate) AS StartDate,
Max(a.ServicesDate) AS LastDate, Max(a.ServicesDate)-
Min(a.ServicesDate)+1 AS NumberOfDays
FROM qryConsecutiveDateCountPrep2 AS a
WHERE ServicesType="Men's Dorm"
GROUP BY a.ServicesID, a.ServicesDate-a.Rank;
When I run them, I get a count of the number of days between the date
the guest first stayed and the last date the guest stayed. So, if a
guy stayed on February 1st for the first time and again on the 16th,
17th, and 18th. I would get "18" as the total number of days. But, I
want the total number of consecutive days prior to today. So, in this
case, I would be looking for "3" (assuming today is the 19th).
If this isn't possible, how would I at least get the number of stays
for the current month.