The expected end result is not very clear, but indeed, if you have two
tables:
Orders
OrderID, ItemID, Qty, ...
and
Receptions
ShipmentID, OrderID, ItemID, Qty, ...
where, for one order, one item, you may have many records in Receptions, you
can then SUM the quantity over the items to know which items are still in
back order:
SELECT OrderID, ItemID, SUM(qty) AS totalReceived
FROM receptions
GROUP BY OrderID, itemID
as saved query, say q1, then
SELECT orderID, ItemID, qty-Nz(q1.totalReceived, 0)
FROM orders LEFT JOIN receptions
ON orders.orderID = receptions.orderID
WHERE qty-Nz(q1.totalReceived, 0) > 0
would give you the items ID (by order id) which are still back order.
If you have just one table, that would be even easier, uisng + for ordered
quantity, and - for received ones. Get one record per reception, and then,
simply :
SELECT orderID, itemID, SUM(qty)
FROM oneTable
GROUP BY orderID, itemID
HAVING SUM(qty) > 0
You don't have to 'manually' update any records, just USE the query with the
SUM when and where you need the 'updated' sum. That won't take much more
time, and will always be up to date.
Vanderghast, Access MVP
"angie" <(E-Mail Removed)> wrote in message
news:AFAC49D5-0F9A-44EE-BC56-(E-Mail Removed)...
>i have two tables as follows:
>
> orders table, fields: order number, quantity ordered, shipment code.
>
> invoices table, fields: order number, quantity received.
>
> most of the times our supplier does not ship all the quantities ordered.
> so
> this means that backorder items should be updated with a new shipment
> code. i
> cannot figure out the best way to do this because i have multiple entries
> of
> items with the same order number in both tables.
>
> i was thinking of creating a series of queries that would add records with
> negative quantities in the orders table with the initial shipment code and
> add positive quantities in the same table with a new shipment code.
>
> can anyone make a suggestion? i have been doing all the updates manually
> and it is really time consuming!!!
|