InventoryId PartId WarehouseId LocationId LocationInfo SerialNo Quantity Received ----------- ------- ----------- ----------- ------------- --------- -------- -------- 2254 1 2 6 Some Info ABC-123 1 1 2138 1 2 0 NULL XYZ-456 1 1 2137 1 1 1 More Info NULL 1 1And when the part is NOT received:
InventoryId PartId WarehouseId LocationId LocationInfo SerialNo Quantity Received ----------- ------- ----------- ----------- ------------- --------- -------- -------- 2138 1 2 0 NULL XYZ-456 1 0 2137 1 1 1 More Info NULL 1 1Then when the Warehouse receives that Part you should update that field to 1 for the empty record and then add a new record.
CREATE PROCEDURE ap_GetPartsNotReceived @WarehouseId INT AS BEGIN SELECT p.PartNo, i.SerialNo AS Serial, l.Location, i.LocationInfo, i.PurchaseOrder, p.Description, u.FullName, w.Caption AS Warehouse, w.WarehouseCode, i.* FROM Inventory i JOIN Parts p ON p.PartId = i.PartId JOIN Warehouses w ON w.WarehouseId = i.WarehouseId JOIN Users u ON u.UserId = i.UserId FULL JOIN Locations l ON l.LocationId = i.LocationId WHERE i.WarehouseId = @WarehouseId AND i.LocationId = 0 AND i.Received = 0 ORDER BY p.PartNo, i.SerialNo>I'm have this Inventory table
>InventoryId PartId WarehouseId LocationId LocationInfo SerialNo Quantity >----------- ------- ----------- ----------- ------------- --------- --------- >2254 1 2 6 Some Info ABC-123 1 >2138 1 2 0 NULL XYZ-456 1 >2137 1 1 1 More Info NULL 1 > >>
>CREATE PROCEDURE ap_GetPartsNotReceived > @WarehouseId INT > >AS >BEGIN > > SELECT p.PartNo, i.SerialNo AS Serial, l.Location, i.LocationInfo, i.PurchaseOrder, > p.Description, u.FullName, > w.Caption AS Warehouse, w.WarehouseCode, i.* > FROM Inventory i > JOIN Parts p ON p.PartId = i.PartId > JOIN Warehouses w ON w.WarehouseId = i.WarehouseId > JOIN Users u ON u.UserId = i.UserId > FULL JOIN Locations l ON l.LocationId = i.LocationId > WHERE i.WarehouseId = @WarehouseId AND > i.LocationId = 0 > ORDER BY p.PartNo, i.SerialNo > >>