--SELECT ROW_NUMBER() OVER (ORDER BY FEntryID) AS FNO,FEntryID, (FAuxQty-FAuxCommitQty) AS FunQty INTO #SEOutStockEntry2016 FROM SEOutStockEntry WHERE finterid=3925
--SELECT * FROM #SEOutStockEntry2016
--insert INTO #SEOutStockEntry2016
--SELECT 4,4,10
declare @NetWeight as numeric(23,4) --总数量
declare @conutSEOut as int --总行数
declare @i as int
declare @FunQty as numeric(23,4) --未出来数量
declare @totalQty as numeric(23,4)
declare @YFPqty as numeric(23,4) --已分配数量
declare @funFPQty as numeric(23,4) --剩余分配数量
SET @YFPqty=0
SET @totalQty=0
SET @i=1
SET @NetWeight=1
SET @funFPQty=1
SET @conutSEOut=(SELECT COUNT(*) FROM #SEOutStockEntry2016 )
--SET @totalQty=(SELECT sum(FunQty) FROM #SEOutStockEntry2016)
--判断实发数量是否 大于 第一行的开单数量
WHILE @i < =@conutSEOut
BEGIN
SELECT @FunQty=FunQty FROM #SEOutStockEntry2016 WHERE FNO=@i
IF @FunQty<>0
BEGIN
IF @funFPQty > @FunQty
BEGIN
print @i
print @FunQty
SET @YFPqty=@FunQty
SET @funFPQty=@NetWeight-@YFPqty
END
ELSE
BEGIN
print @i
print @NetWeight-@totalQty
SET @YFPqty=@NetWeight-@totalQty
END
SET @totalQty=@totalQty+@YFPqty
IF @totalQty=@NetWeight
BEGIN
BREAK
END
END
SET @i=@i+1
END