E
Executor
Query elapsed time sequential history moments.
Hi to All,
I have a Table "StatusHistory"designed as:
PK, AutoNumer, Primary Key
FK_Invoice, Long, Foreign Key to Invoices_Table
FK_Status, Long, Foreign Key to Statuses_Table
Date_Assigned, DateTime, Date the status changed.
I have these records:
1, 1, 1, 23 march 2005
2, 1, 2, 25 march 2005
3, 1, 3, 28 march 2005
4, 2, 1, 24 march 2005
5, 1, 4, 30 march 2005
6, 2, 2, 25 march 2005
I want to query the time elapsed between each status change.
Invoice, StatusFrom, DateFrom, StatusTo, DateTo, Elapsed.
I have tried:
SELECT I.FK_Invoice, I.FK_Status AS StatusFrom, I.Date_Assigned AS
DateFrom, S.FK_Status AS StatusTo, Min(S.Date_Assigned) AS DateTo,
DateDiff("d",[DateFrom],[dateTo]) AS Elapsed
FROM StatusHistory AS I INNER JOIN StatusHistory AS S ON I.FK_Invoice =
S.FK_Invoice
GROUP BY I.FK_Invoice, I.FK_Status, I.Date_Assigned, S.FK_Status
HAVING (((Min(S.Date_Assigned))>[I.Date_Assigned]));
Result:
FK_Invoice; StatusFrom; DateFrom; StatusTo; DateTo; Elapsed
1; 1; 23-3-2005; 2; 25-3-2005; 2
1; 1; 23-3-2005; 3; 28-3-2005; 5
1; 1; 23-3-2005; 4; 30-3-2005; 7
1; 2; 25-3-2005; 3; 28-3-2005; 3
1; 2; 25-3-2005; 4; 30-3-2005; 5
1; 3; 28-3-2005; 4; 30-3-2005; 2
2; 1; 24-3-2005; 2; 25-3-2005; 1
But this will give me also the time elapsed between the first and de
third record and the time between the first and the fifth record. I am
not interested in these two.
I can not use the difference between two status values, because I do
not know what the status values will be when the program is in use. And
I suspect that at some time the status of an invoice can be set back in
reaction on a complaint by the customer.
So my question is: How to get only the sequential dates from my status
history?
Thank in advance,
Hi to All,
I have a Table "StatusHistory"designed as:
PK, AutoNumer, Primary Key
FK_Invoice, Long, Foreign Key to Invoices_Table
FK_Status, Long, Foreign Key to Statuses_Table
Date_Assigned, DateTime, Date the status changed.
I have these records:
1, 1, 1, 23 march 2005
2, 1, 2, 25 march 2005
3, 1, 3, 28 march 2005
4, 2, 1, 24 march 2005
5, 1, 4, 30 march 2005
6, 2, 2, 25 march 2005
I want to query the time elapsed between each status change.
Invoice, StatusFrom, DateFrom, StatusTo, DateTo, Elapsed.
I have tried:
SELECT I.FK_Invoice, I.FK_Status AS StatusFrom, I.Date_Assigned AS
DateFrom, S.FK_Status AS StatusTo, Min(S.Date_Assigned) AS DateTo,
DateDiff("d",[DateFrom],[dateTo]) AS Elapsed
FROM StatusHistory AS I INNER JOIN StatusHistory AS S ON I.FK_Invoice =
S.FK_Invoice
GROUP BY I.FK_Invoice, I.FK_Status, I.Date_Assigned, S.FK_Status
HAVING (((Min(S.Date_Assigned))>[I.Date_Assigned]));
Result:
FK_Invoice; StatusFrom; DateFrom; StatusTo; DateTo; Elapsed
1; 1; 23-3-2005; 2; 25-3-2005; 2
1; 1; 23-3-2005; 3; 28-3-2005; 5
1; 1; 23-3-2005; 4; 30-3-2005; 7
1; 2; 25-3-2005; 3; 28-3-2005; 3
1; 2; 25-3-2005; 4; 30-3-2005; 5
1; 3; 28-3-2005; 4; 30-3-2005; 2
2; 1; 24-3-2005; 2; 25-3-2005; 1
But this will give me also the time elapsed between the first and de
third record and the time between the first and the fifth record. I am
not interested in these two.
I can not use the difference between two status values, because I do
not know what the status values will be when the program is in use. And
I suspect that at some time the status of an invoice can be set back in
reaction on a complaint by the customer.
So my question is: How to get only the sequential dates from my status
history?
Thank in advance,