O
Onno
Hi, I have this db-structure:
tblActionTypes
1 ..
2 ..
3 = BatchStart
4 = BatchEnd
5 = CaseStart
6 = CaseEnd
etc
tblUsage
[AutoIncrID] [ActionTime] [ActionType] [Name] [TransActionID]
In this tblUsage, apps from all over the plant log their usage data,
mainly start & stops of some different action type. The
[TransActionID] contains a generated GUID that is the same for 2 rows
that belong together. (i.e.a BatchStart and BatchEnd that belong
together have the same TransActionID. This way I can easily match
them.
The table can look something like this:
1 2008-09-03 14:33:11 3 MyBatch1 <guid-AA>
2 2008-09-03 14:35:11 4 MyBatch1 <guid-AA>
3 2008-09-03 14:35:12 5 MyCase1 <guid-BB>
4 2008-09-03 14:35:13 3 MyBatch2 <guid-CC>
5 2008-09-03 14:36:00 6 MyCase1 <guid-BB>
6 2008-09-03 14:39:12 4 MyBatch2 <guid-CC>
7 2008-09-03 16:00:00 3 MyBatch1 <guid-DD>
8 2008-09-03 16:00:11 4 MyBatch1 <guid-DD>
I want to create a report that contains an overview of the running
time of all distinct batches, i.e. the sum of all BatchEnd-BatchStart
ActionTimes for all distinct batches in a period. How can I do this
with any kind of decent performance? Given the above example, the
report looks like this:
[Name] [NrRuns] [Time]
MyBatch1 2 ...
MyBatch2 1 ...
I do this now via loops in VBA, but this is horribly slow. My current
code is something like this:
distinctBatches = DAO.RecordSet(SELECT DISTINCT NAME FROM tblUsage
WHERE [ActionType]=3
AND [ActionTime]
within date range)
While not distinctBatches.EOF
thisBatchExecutions = Recordset(SELECT [ActionTime], [ActionType],
[TransactionID] FROM tblUsage
WHERE
([ActionType]=3 OR [ActionType=4]) AND within date range
AND
[Name] = distinctBatches!Name)
Do While Not thisBatchExecutions.EOF
If thisBatchExecutions!ActionType = 3 Then ' On a start
endTime = DLookup("[ActionTime]", "tblUsage", _ ' Loopup end
time
"[ActionType]=4 AND within date
range
AND [TransactionID]
=thisBatchExecutions!transactionID)
if found, add endTimes, etc.
End if
Loop
Loop
I can’t figure out how to do this without the loops using SQL.
Can anyone offer some assistance?
TIA,
Onno
tblActionTypes
1 ..
2 ..
3 = BatchStart
4 = BatchEnd
5 = CaseStart
6 = CaseEnd
etc
tblUsage
[AutoIncrID] [ActionTime] [ActionType] [Name] [TransActionID]
In this tblUsage, apps from all over the plant log their usage data,
mainly start & stops of some different action type. The
[TransActionID] contains a generated GUID that is the same for 2 rows
that belong together. (i.e.a BatchStart and BatchEnd that belong
together have the same TransActionID. This way I can easily match
them.
The table can look something like this:
1 2008-09-03 14:33:11 3 MyBatch1 <guid-AA>
2 2008-09-03 14:35:11 4 MyBatch1 <guid-AA>
3 2008-09-03 14:35:12 5 MyCase1 <guid-BB>
4 2008-09-03 14:35:13 3 MyBatch2 <guid-CC>
5 2008-09-03 14:36:00 6 MyCase1 <guid-BB>
6 2008-09-03 14:39:12 4 MyBatch2 <guid-CC>
7 2008-09-03 16:00:00 3 MyBatch1 <guid-DD>
8 2008-09-03 16:00:11 4 MyBatch1 <guid-DD>
I want to create a report that contains an overview of the running
time of all distinct batches, i.e. the sum of all BatchEnd-BatchStart
ActionTimes for all distinct batches in a period. How can I do this
with any kind of decent performance? Given the above example, the
report looks like this:
[Name] [NrRuns] [Time]
MyBatch1 2 ...
MyBatch2 1 ...
I do this now via loops in VBA, but this is horribly slow. My current
code is something like this:
distinctBatches = DAO.RecordSet(SELECT DISTINCT NAME FROM tblUsage
WHERE [ActionType]=3
AND [ActionTime]
within date range)
While not distinctBatches.EOF
thisBatchExecutions = Recordset(SELECT [ActionTime], [ActionType],
[TransactionID] FROM tblUsage
WHERE
([ActionType]=3 OR [ActionType=4]) AND within date range
AND
[Name] = distinctBatches!Name)
Do While Not thisBatchExecutions.EOF
If thisBatchExecutions!ActionType = 3 Then ' On a start
endTime = DLookup("[ActionTime]", "tblUsage", _ ' Loopup end
time
"[ActionType]=4 AND within date
range
AND [TransactionID]
=thisBatchExecutions!transactionID)
if found, add endTimes, etc.
End if
Loop
Loop
I can’t figure out how to do this without the loops using SQL.
Can anyone offer some assistance?
TIA,
Onno