How do I make the update work for all the records not just the unique records?
UPDATE Inventory.Inventory
SET Qty = Inventory.Inventory.Qty - Retail.OrderDetails.Qty FROM Inventory.Inventory INNER JOIN
Retail.OrderDetails ON Inventory.Inventory.Code = Retail.OrderDetails.Code
WHERE (Retail.OrderDetails.Invoice = 207070202)
Thanks
Quote:
Originally Posted by Kliot
I am trying to update a master inventory table from an order details table, the query below works fine except when the order details table contains the same code number multiple times. When this occurs the update only updates for the first instance of the code number.
How do I make the update work for all the records not just the unique records?
UPDATE Inventory.Inventory
SET Qty = Inventory.Inventory.Qty - Retail.OrderDetails.Qty FROM Inventory.Inventory INNER JOIN
Retail.OrderDetails ON Inventory.Inventory.Code = Retail.OrderDetails.Code
WHERE (Retail.OrderDetails.Invoice = 207070202)
Thanks
I think it is not possible in SQL Server. But it will work in MS Access.
You have to fetch record and then update it|||hi
i have gone through ur query, but if possible just send me 1 or two records of each table and tell me exactily what u want|||Here is an example,
Invoice table
Code|||Here is an example,
Invoice table
Code Quantity
DM01 2
LG02 2
DM01 3
QP76 1
The update query will update the Inventory table quantity for DM01 by 2 not 5, the second DM01 is not updated
I can get around this by doing a sum query inside the select but it's not ideal.
UPDATE Inventory.Inventory
set RQty = Inventory.Inventory.RQty - od.Quantity
FROM (SELECT Code, SUM(Quantity) AS Quantity FROM Retail.OrderDetails WHERE Invoice = 207022101
GROUP BY Code) as od WHERE(Inventory.inventory.code = od.code)
No comments:
Post a Comment