Bibi:
If I understand you correctly you just need to subtract the beginning date of
the next lease from the end date of the current lease:
SELECT L1.[Property ID], L1.[Lease Begins],
L1.[Lease Ends],
(SELECT MIN(L2.[Lease Begins])
FROM Leases As L2
WHERE L2.[Lease Begins] > L1.[Lease Ends]
AND L2.[Property ID] = L1.[Property ID])
- L1.[Lease Ends] AS DaysVacant
FROM Leases AS L1
ORDER BY L1.[Property ID], L1.[Lease Begins];
You can then base another query on this, grouping by MONTH([Lease Ends]) and
returning the AVG(DaysVacant).
Ken Sheridan
Stafford, England
HELP! I goofed up. I was not clear enough in stating what I actually needed
from this query. I need to be able to calculate the average number of days
an apartment is vacant BUT the number of days vacant needs to be associated
with the month the original lease ended. Initially the data looked great but
then....I realized that the number of days vacant is being associated with
the new (beginning lease) not the expiring lease..... so the results I get
are not usable to help decide if we should no longer write leases expiring in
a certain month based on how long it takes to find a new tenant.........I
hope this is clearer and you can help!
TIA
Bibi
I don't think you need the INNER JOIN here as the join criteria are in the
WHERE clause, but I'd normally include the subquery in the SELECT clause for
[quoted text clipped - 53 lines]
Ummm... could you post the actual SQL you're using? I can't see it from here.
--
.