Hello,
I have some intricate needs for a query that I'm tooling around with in Microsoft Access to generate a report based on SQL data that exists in my DB. Any insight on how I can adjust this query so that it will not take FOREVER to load a count of rows? Our out of the box order system has delivery dates displayed in a different table then that of the rest of the data which also displays delivery dates for each line item (so not PER order). The problem is that I just need a DISTINCT count of one for each row in that table to generate a total order count for the day.
Here is the query.. Any insight would be great. It eventually displays, but takes 5-15 minutes on only 1-200 orders and that seems pretty ridiculous to me. I need the overall count(*) since I need a single number for the entire query to display how many orders there are for that given day. Displaying all of the orders and grouping them in a huge list doesn't really help me when printing a single digit onto a report.
e = "SELECT COUNT(*) AS OrderCount " & _
"FROM (SELECT DISTINCT OrderNumber FROM OrderDetails WHERE DateShipped=Format(Date()+1,'mm/dd/yyyy') And OrderDetails.OrderNumber NOT IN (SELECT OrderNumber FROM Orders WHERE Cancelled=TRUE) And OrderDetails.OrderNumber IN (SELECT OrderNumber FROM Orders WHERE Orders.Shipping NOT LIKE 'Ground' AND Orders.Shipping NOT LIKE 'Ground Residential w/Saturday' AND Orders.Shipping NOT LIKE 'Office Pickup' AND Orders.Shipping NOT LIKE 'Store Pickup' AND Orders.Shipping NOT LIKE 'SPREADSHEET' AND Orders.Shipping NOT LIKE 'Customer Pickup'))"
Set rs = CurrentDb.OpenRecordset(e)
Me.txtOrdertotCount = rs!OrderCount
rs.Close
I'm basically looking for "a single total order count of all orders that contain a DISTINCT (1) of however many items in the order that have a shipdate of tomorrow which should not contain orders that are cancelled and should only include the specific shipping types not listed".
Any insight would be great. I've been mulling tons of options over all morning and getting this more simplified has been somewhat uneventful thus far.
Thanks!
I have some intricate needs for a query that I'm tooling around with in Microsoft Access to generate a report based on SQL data that exists in my DB. Any insight on how I can adjust this query so that it will not take FOREVER to load a count of rows? Our out of the box order system has delivery dates displayed in a different table then that of the rest of the data which also displays delivery dates for each line item (so not PER order). The problem is that I just need a DISTINCT count of one for each row in that table to generate a total order count for the day.
Here is the query.. Any insight would be great. It eventually displays, but takes 5-15 minutes on only 1-200 orders and that seems pretty ridiculous to me. I need the overall count(*) since I need a single number for the entire query to display how many orders there are for that given day. Displaying all of the orders and grouping them in a huge list doesn't really help me when printing a single digit onto a report.
e = "SELECT COUNT(*) AS OrderCount " & _
"FROM (SELECT DISTINCT OrderNumber FROM OrderDetails WHERE DateShipped=Format(Date()+1,'mm/dd/yyyy') And OrderDetails.OrderNumber NOT IN (SELECT OrderNumber FROM Orders WHERE Cancelled=TRUE) And OrderDetails.OrderNumber IN (SELECT OrderNumber FROM Orders WHERE Orders.Shipping NOT LIKE 'Ground' AND Orders.Shipping NOT LIKE 'Ground Residential w/Saturday' AND Orders.Shipping NOT LIKE 'Office Pickup' AND Orders.Shipping NOT LIKE 'Store Pickup' AND Orders.Shipping NOT LIKE 'SPREADSHEET' AND Orders.Shipping NOT LIKE 'Customer Pickup'))"
Set rs = CurrentDb.OpenRecordset(e)
Me.txtOrdertotCount = rs!OrderCount
rs.Close
I'm basically looking for "a single total order count of all orders that contain a DISTINCT (1) of however many items in the order that have a shipdate of tomorrow which should not contain orders that are cancelled and should only include the specific shipping types not listed".
Any insight would be great. I've been mulling tons of options over all morning and getting this more simplified has been somewhat uneventful thus far.
Thanks!