I have a collection of orders that were submitted to an internal ERP, which were processed and partially shipped.
The table hierarchy is as follows:
Order
table containsOrderReference(PO), OrderID
OrderItems
table containsProduct/Lot/Qty
requested (OrderID
isparentID
that joins these tables)Shipping
containsOrderReference(PO), ShippingID
ShippingArchive
containsProduct/Lot/Qty
that was shipped (ShippingID
is parent that joins these tables)
I want to create a report that looks as follows:
OrderReference#
Order Requested / Shipped Items / Missing Pieces
PC/Lot/Qty - PC/Lot/Qty - PC/Lot/Qty
I have used a temp table to get some of the data but I realize I'm taking the wrong approach. I should be able to do all of this with a single query, though it will seemingly be a bit complex.
I get held up when I try to think about how to join where pieces don't exist, and where to perform the mathematics in my sorting and filtering. Please help!
Sincere thanks 🙂
Best Answer
I think this is what you want. I had to make a few assumptions though. First that a given item is identified by
product
andlot
. So I added a join betweenShippingArchive
andOrderItems
based on these columns. Next that in your report you only needed to see theproduct
andlot
information once and needed therequested
,shipped
andmissing
information forqty
only. I also made the assumption thatmissing
meantrequested-shipped
.Edited to handling multiple shipping for the same order.