Hi all,
Hope someone can help with a query that is running slowly if I enter a WHERE clause.
Basically I have a query that pulls data from three tables and has another field which checks a folder on a network drive to see if a document exists. This works fine and opens up instantaneously.
Here is the SQL from that query :
I also have another query which is almost exactly the same but has a where clause in the InvoiceExists field to filter for rows that have either "NO" Or "No Invoice Loaded" in the InvoiceExists field. When I add the WHERE clause the query takes 10 - 30 seconds to open. I think this is very slow( I may be wrong) as there is only 100 - 150 rows out of the 3000 in the table that get returned.
Here is the SQL from that query :
I have also tried basing the second Query on the first one with the WHERE clause but there is no difference in speed.
Thanks
Gareth
Hope someone can help with a query that is running slowly if I enter a WHERE clause.
Basically I have a query that pulls data from three tables and has another field which checks a folder on a network drive to see if a document exists. This works fine and opens up instantaneously.
Here is the SQL from that query :
Code:
SELECT PO045.BinNo, PO045.PartNo, PO045.Description, PO045.Qty, PO045.Supplier, PO045.PONo, PO045.GRNo, PO045.InvoiceNo, PO045.DateRecieved, PO045.Active, TblClaimGroups.ClaimGroupID, TblClaimGroups.ClaimAmount, TblProducts.Claimable, Format([Qty]*[ClaimAmount],"Currency") AS LineTotal, IIf(IsNull([InvoiceNo]),"No Invoice Loaded",CheckInvoiceExists([InvoiceNo])) AS InvoiceExists
FROM PO045 INNER JOIN (TblClaimGroups INNER JOIN TblProducts ON TblClaimGroups.[ClaimGroupID] = TblProducts.[ClaimGroupID]) ON PO045.BinNo = TblProducts.BinNo
WHERE (((PO045.Supplier)<>"Even" And (PO045.Supplier)<>"trent") AND ((PO045.Active)=True) AND ((TblProducts.Claimable)=True) AND ((IIf(IsNull([InvoiceNo]),"No Invoice Loaded",CheckInvoiceExists([InvoiceNo])))="No")) OR (((IIf(IsNull([InvoiceNo]),"No Invoice Loaded",CheckInvoiceExists([InvoiceNo])))="No Invoice Loaded"))
ORDER BY PO045.BinNo;
I also have another query which is almost exactly the same but has a where clause in the InvoiceExists field to filter for rows that have either "NO" Or "No Invoice Loaded" in the InvoiceExists field. When I add the WHERE clause the query takes 10 - 30 seconds to open. I think this is very slow( I may be wrong) as there is only 100 - 150 rows out of the 3000 in the table that get returned.
Here is the SQL from that query :
Code:
SELECT PO045.BinNo, PO045.PartNo, PO045.Description, PO045.Qty, PO045.Supplier, PO045.PONo, PO045.GRNo, PO045.InvoiceNo, PO045.DateRecieved, PO045.Active, TblClaimGroups.ClaimGroupID, TblClaimGroups.ClaimAmount, TblProducts.Claimable, Format([Qty]*[ClaimAmount],"Currency") AS LineTotal, IIf(IsNull([InvoiceNo]),"No Invoice Loaded",CheckInvoiceExists([InvoiceNo])) AS InvoiceExists
FROM PO045 INNER JOIN (TblClaimGroups INNER JOIN TblProducts ON TblClaimGroups.[ClaimGroupID] = TblProducts.[ClaimGroupID]) ON PO045.BinNo = TblProducts.BinNo
WHERE (((PO045.Supplier)<>"Even" And (PO045.Supplier)<>"trent") AND ((PO045.Active)=True) AND ((TblProducts.Claimable)=True) AND ((IIf(IsNull([InvoiceNo]),"No Invoice Loaded",CheckInvoiceExists([InvoiceNo])))="No" Or (IIf(IsNull([InvoiceNo]),"No Invoice Loaded",CheckInvoiceExists([InvoiceNo])))="No Invoice Loaded"))
ORDER BY PO045.BinNo;
I have also tried basing the second Query on the first one with the WHERE clause but there is no difference in speed.
Thanks
Gareth