Hi Everyone -
I am having a problem with a query I have created. I have a query called qryDockRuns that runs perfect and within seconds the records appear. However, when I use that query to create another query and add a sequence number field, the query runs unacceptably slow. I don't even know how long it would actually take to get the results since I have never waited beyond 30 minutes for it to finish.
This is the sql for the query I am having problems with:
INSERT INTO tblDockRunsNumbered ( Sequence, EmployeeID, Employee, [Date], RunTime, Type, [Container], StopLocation, [From], [To] )
SELECT IIf([StopLocation]="Door",0,(SELECT Count(*) FROM qryDockRuns AS T WHERE T.EmployeeID = qryDockRuns.EmployeeID AND T.RecordNumber < qryDockRuns.RecordNumber And T.StopLocation <> "Door" And T.RunTime > DMax("RunTime", "qryDockRuns", "EmployeeID=" & T.EmployeeID & " And StopLocation='Door' And Date=#" & qryDockRuns.Date & "# And RunTime<#" & qryDockRuns.RunTime & "#"))+1) AS Sequence, qryDockRuns.EmployeeID, qryDockRuns.Employee, qryDockRuns.Date, qryDockRuns.RunTime, qryDockRuns.Type, qryDockRuns.Container, qryDockRuns.StopLocation, qryDockRuns.From, qryDockRuns.To
FROM qryDockRuns
ORDER BY qryDockRuns.EmployeeID, qryDockRuns.Date, qryDockRuns.RunTime;
If anyone has any suggestions on something that I can change I would greatly appreciate it.
Thank you in advance.
I am having a problem with a query I have created. I have a query called qryDockRuns that runs perfect and within seconds the records appear. However, when I use that query to create another query and add a sequence number field, the query runs unacceptably slow. I don't even know how long it would actually take to get the results since I have never waited beyond 30 minutes for it to finish.
This is the sql for the query I am having problems with:
INSERT INTO tblDockRunsNumbered ( Sequence, EmployeeID, Employee, [Date], RunTime, Type, [Container], StopLocation, [From], [To] )
SELECT IIf([StopLocation]="Door",0,(SELECT Count(*) FROM qryDockRuns AS T WHERE T.EmployeeID = qryDockRuns.EmployeeID AND T.RecordNumber < qryDockRuns.RecordNumber And T.StopLocation <> "Door" And T.RunTime > DMax("RunTime", "qryDockRuns", "EmployeeID=" & T.EmployeeID & " And StopLocation='Door' And Date=#" & qryDockRuns.Date & "# And RunTime<#" & qryDockRuns.RunTime & "#"))+1) AS Sequence, qryDockRuns.EmployeeID, qryDockRuns.Employee, qryDockRuns.Date, qryDockRuns.RunTime, qryDockRuns.Type, qryDockRuns.Container, qryDockRuns.StopLocation, qryDockRuns.From, qryDockRuns.To
FROM qryDockRuns
ORDER BY qryDockRuns.EmployeeID, qryDockRuns.Date, qryDockRuns.RunTime;
If anyone has any suggestions on something that I can change I would greatly appreciate it.
Thank you in advance.