i have created a simple access POS database and have the following tables products and order details, orders amongst others, the products table has a unitsinstock column and the order details has a quantiy column. What im trying to do is create an update query that i will execute once a day via a button at the end of the day that will sum the number of units sold per productid and subtract this value from the units in stock(products.unitsinstock) per unit productid...the select statements below gives these values but when i try to create an update table based on this it doesnt work, my update query is as follows:-
Update Query
units soldUPDATE products SET products.UnitInStock = products.UnitInStock - (
SELECT SUM([order details].Quantity)
FROM [order details]
WHERE [order details].ProductID = products.ProductID);
Units in StockSELECT Orders.OrderDate, [Order Details].ProductID, Sum([Order Details].Quantity) AS [Total Sold]
FROM Orders INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID
GROUP BY Orders.OrderDate, [Order Details].ProductID
any help will be appreciated, im trying to avoid having to subtract the products.unitsinstock=(products.unitsinstock -[order details].quantity) every time a product is soldSELECT Products.ProductID,
Products.ProductName, Products.CategoryID,
Products.QuantityPerUnit,
Products.UnitsInStock, Products.ReorderLevel
FROM Products;