I have two tables in an Access 2016 application: Customer, and CustomerLoggedHours. This is a one to many relationship.
I want to select records based on the sum of a field value in the detail table. I have tried several approaches, but none has worked. I get the error 3096 - cannot have an aggregate function in WHERE clause. Is there any way to allow me to sum the hours to calculate a total so I can determine if the hours purchased have been consumed by the customer?
Here is my SQL:
INSERT INTO tblCustomerArchive
(CustID, CustomerName, DateOfPurchase, ExpireDate, PurchaseAmount, HoursPurchased, DateArchived)
(SELECT CustID, CustomerName, DateOfPurchase, ExpireDate, PurchaseAmount, HoursPurchased, Date FROM Customer INNER JOIN CustomerLoggedHours ON Customer.ID = CustomerLoggedHours.CustID
WHERE Customer.ExpireDate < Date
OR (SUM(CustomerLoggedHours.HoursLogged - Customer.HoursPurchased <= 0))
GROUP BY CustomerLoggedHours.CustID
I want to select records based on the sum of a field value in the detail table. I have tried several approaches, but none has worked. I get the error 3096 - cannot have an aggregate function in WHERE clause. Is there any way to allow me to sum the hours to calculate a total so I can determine if the hours purchased have been consumed by the customer?
Here is my SQL:
INSERT INTO tblCustomerArchive
(CustID, CustomerName, DateOfPurchase, ExpireDate, PurchaseAmount, HoursPurchased, DateArchived)
(SELECT CustID, CustomerName, DateOfPurchase, ExpireDate, PurchaseAmount, HoursPurchased, Date FROM Customer INNER JOIN CustomerLoggedHours ON Customer.ID = CustomerLoggedHours.CustID
WHERE Customer.ExpireDate < Date
OR (SUM(CustomerLoggedHours.HoursLogged - Customer.HoursPurchased <= 0))
GROUP BY CustomerLoggedHours.CustID