|
MorrisK
Yak Posting Veteran
83 Posts |
Posted - 2011-12-21 : 09:39:53
|
| I've been given a task here at year end to take lot quantities and spread them (allocate them?) across requirements. I think I can loop through it but I'm hoping somone can show me a better way.Here's some background - There are multiple kits.Each kit requires multiple components.Each component may have multiple lots.Some lot quantities may be more than required by one kit, some less.Please see if this makes any sense. I greatly appreciate any suggestions.Thanks,KevinDECLARE @Kits TABLE( KitNumber INT IDENTITY(1,1),KitStockCode CHAR(30),Component INT,ComponentQtyReqd DECIMAL(10,3),ComponentQtyAllocated DECIMAL(10,3),Complete CHAR(1))DECLARE @Lots TABLE( LotNumber INT IDENTITY(1,1),Component INT,LotQty DECIMAL(10,3),LotQtyAllocated DECIMAL(10,3))INSERT INTO @Kits(KitStockCode, Component, ComponentQtyReqd, ComponentQtyAllocated, Complete)VALUES('A', 1, 100, 0, 'N')INSERT INTO @Kits(KitStockCode, Component, ComponentQtyReqd, ComponentQtyAllocated, Complete)VALUES('B', 1, 100, 0, 'N')INSERT INTO @Kits(KitStockCode, Component, ComponentQtyReqd, ComponentQtyAllocated, Complete)VALUES('C', 1, 100, 0, 'N')SELECT * FROM @KitsINSERT INTO @Lots(Component, LotQty, LotQtyAllocated)VALUES(1, 150, 0)INSERT INTO @Lots(Component, LotQty, LotQtyAllocated)VALUES(1, 75, 0)SELECT * FROM @Lots--Need to produce something like thisUPDATE @KitsSET Complete = 'Y',ComponentQtyAllocated = ComponentQtyReqdWHERE KitNumber IN (1, 2)AND Component = 1UPDATE @KitsSET ComponentQtyAllocated = 25WHERE KitNumber IN (3)AND Component = 1SELECT * FROM @Kits--And put this in a table--KitNumber KitStockCode Component Lot LotQtyAllocated --1 A 1 1 100--2 B 1 1 50--2 B 1 2 50--3 C 1 2 25 |
|