Hi,
I'm trying to create a select statement that will show me:
- orderlines that don't have a corrsponding location record (meaning: that orderline was not picked in a warehouse)
OR - orderlines where the total of the quantities of the corresponding location record(s) are less than the quantity that was ordered (meaning not all items could be picked)
This is what I have so far:
select OutgoingDetails.OrderLineDescription,outgoingdetails.Quantity, outgoingdetails.SessionId,
OutgoingLocation.LocationId, outgoinglocation.Quantity,
OutgoingSessionDelivery.DeliveryNumber,
customer.CustomerName
from OutgoingDetails
left join OutgoingLocation on OutgoingDetails.Id = OutgoingLocation.OutgoingDetailsId
left join OutgoingSessionDelivery on outgoingdetails.SessionId = OutgoingSessionDelivery.SessionId
left join Customer on OutgoingSessionDelivery.CustomerId = Customer.Id
where outgoingdetails.SessionId = 122 and outgoinglocation.LocationId is null
This is fine. This is the case where there is no location found, meaning there was no stock at all. I want to see this record.
However, sometimes an orderline is picked on one, or two or more locations, and only if the sum of the picked quantities on these location(s) is less than the quantiy that was ordered, they should be in my result set too.
But if the sum of the quantities is equal, then it should be excluded.
Here's an example where the result should be excluded. the 2 records highlighted in blue. the sum of the 2 quantity records (the second quantity column) is 3+1 = 4. This is equal to the first quantity column . So the 4 items have been all picked in 2 locations, which is fine, and should be excluded from the result.
I don't know how to exclude this type of record, and I also need to combine both possibilities in 1 select statement.
I hope I explained this well enough so that someone can help me.
Thanks,
Tom