This query is slow using MS Access 2000 as a backend, but it gets slower (4 hours or more) using SQL Server 2008 Express as the backend. Is there any way you can see to improving the performance?
The indexes for tblARTransactions are:
composite Primary Key (ARTransDate, ContractID, ARTransTypeID, Sequence)
ARTranactionID
ARTransDate & TimeStamp
ContractID
ContractVehicleID
DeleteDTS
EntryDate
and here's the query
SELECT a2.*
FROM tblARTransactions AS a2
WHERE (( (a2.ARTransDate) > DateAdd("d",-5,Date())) AND ((a2.ContractVehicleID) IN
(SELECT a1.ContractVehicleID
FROM tblARTransactions AS a1
WHERE a2.ARTransDate >= DateAdd("d",-1,a1.ARTransDate) AND a2.ARTransDate <= DateAdd("d",1,a1.ARTransDate)
AND a2.ARTransTypeID = a1.ARTransTypeID
AND a2.ARTransactionID <> a1.ARTransactionID
)))
ORDER BY a2.ContractID, a2.ARTransDate DESC;