-----Original Message-----
I have a table that looks like the following:
ID ProgDate
1 1-1-04
1 1-15-04
1 2-4-04
2 1-12-04
2 1-29-04
I need to find out the number of days difference per
ID,i.e. for ID 1:
(1-15-04)-(1-1-04)
(2-1-04) - (1-15-04) and so on.
Any idea how can I accomplish this?
thank you
I'd use a Self Join query or a Subquery and the DateDiff function. If
these are the only two fields that you have, it's going to be a bit
complicated, since there is no intrinsic order to an Access table -
there is no "next record" or "previous record".
A couple of questions: What do you want to do at the end of a run? I
can see that DateDiff("d", #1-1-04#, #1-1-04#) would give you the time
elapsed for the second record - but what value do you want to see for
the first? NULL? What if there's only one date for an ID?
AS WRITTEN, you could try
SELECT T1.ID, T1.ProgDate AS DateStart, T2.ProgDate AS DateEnd,
DateDiff("d", DateStart, DateEnd) AS Elapsed
FROM yourtable AS T1
INNER JOIN yourtable AS T2
ON T1.ID = T2.ID
WHERE T2.ProgDate = DMin("[ProgDate]", "[yourtable]", "[ID] = " &
T1.ID & " AND [ProgDate] > #" & T1.ProgDate & "#");
.