I'd like to start some discussion around inventory discrepancies and how to identify and correct them. I've searched around and seen various threads, but thought we might be able to aggregate some information here. We're looking at doing a periodic correction of inventory. I've been able to identify discrepancies, but have yet to determine best methods to fix them. Ideally the fix would be a stored procedure that we might run on a daily or weekly basis.
Below is a query I've written to help identify our inventory discrepancies. It compares:
- Cost Tier Quantities - timCostTier
- Inventory Lot Quantities - timInvtLotBin
- Warehouse Bin Quantities - timWhseBinInvt
- Calculated Quantity - timInvtTran + timInvtTranCost
You can modify the 'where' clause to filter out the discrepancy types of interest.
Declare @companyid varchar(3), @WhseId varchar(10) Set @CompanyId = 'cbi' Set @WhseID = 'Main' select costtier.itemkey, item.itemid, costtier.QtyOnHand as [Cost Tier QOH], WhseBin.PendQtyDec as [WhseBin PendQtyDec], WhseBin.PendQtyInc as [WhseBin PendQtyInc], WhseBin.QtyOnHand as [WhseBin QOH], Lotbin.QtyOnHand as [LotBin QOH], LotBin.PendQtyDec as [LotBin PendQtyDec], LotBin.PendQtyInc as [LotBin PendQtyInc], TranHist.QtyOnHand as [TranHist QOH], stdcost.materialunitcost * (costtier.qtyonhand - whsebin.qtyonhand) as [Valuation Difference] from (select ctier.WhseKey, item.itemkey, sum(ctier.origqty - ctier.qtyused) as [QtyOnHand] from timcosttier ctier join timitem item on ctier.itemkey = item.itemkey where item.companyid = @CompanyId group by item.itemkey, ctier.WhseKey ) costtier left join (select item.itemkey, sum(pendQtyDecrease) as [PendQtyDec], sum(pendQtyIncrease) as [PendQtyInc], sum(QtyOnHand) as [QtyOnHand] from timWhseBinInvt binInvt join timitem item on binInvt.itemkey = item.itemkey where item.companyid = @CompanyID group by item.itemkey ) whsebin on costtier.itemkey = whsebin.itemkey left join (select item.itemkey, sum(trancost.DistQty * sign(InvtTran.TranQty)) as [QtyOnHand] from timinvttrancost trancost join timinvttran invttran on trancost.invttrankey = invttran.invttrankey join timinvttranlog tranlog on trancost.invttrankey = tranlog.invttrankey join timitem item on invttran.itemkey = item.itemkey where item.companyid = @CompanyID and tranlog.trantype not in (709,716)-- and invttran.trandate >= '2009-1-15' --Date of Implementation (false trans prior to this date?) group by item.itemkey ) TranHist on costtier.itemkey = TranHist.itemkey left join (select item.itemkey, sum(lotbin.OrigQty - lotbin.QtyUsed) as [QtyOnHand], sum(pendQtyDecrease) as [PendQtyDec], sum(pendQtyIncrease) as [PendQtyInc] from timinvtlotbin lotbin join timinvtlot lot on lotbin.invtlotkey = lot.invtlotkey join timitem item on lot.itemkey = item.itemkey where item.companyid = @companyID group by item.itemkey ) LotBin on costtier.itemkey = lotbin.itemkey left join timWarehouse Whse on costtier.whsekey = Whse.whsekey left join timinvtstdunitcost stdcost on costtier.itemkey = stdcost.itemkey join timitem item on costtier.itemkey = item.itemkey where Whse.whseid = @whseid and (costtier.QTYOnHand <> coalesce(WhseBin.QtyOnHand,0)) and item.status = 1 --Active Items order by item.itemid
Any feedback on the query? (Not an SQL master, but always looking to improve)
I've also seen some built in stored procedures that are supposed to help recalculate inventory levels. Sounds like they work with varying degrees of success.
Please share any tools or practices that your organization has adopted.