Poravnanje vrijednosti za nulte zalihe

declare @acWarehouse char (30),

        @adDate datetime,

        @k char (13)

declare xPoz cursor local fast_forward for

SELECT distinct m.acWarehouse, m.datum

                     FROM #lHE_MovePrtActStockPrt1 M JOIN tHE_SetItem M1 on M.acIdent = M1.acIdent

                     LEFT JOIN tHE_SetItemCateg K on M1.acClassif = K.acClassif

                     LEFT JOIN tHE_SetItemCateg K2 on M1.acClassif2 = K2.acClassif

                     LEFT JOIN THE_SetItemPriceForWrh W on W.acIdent = M.acIdent AND W.acWarehouse = M.acWarehouse

                     LEFT JOIN tHE_SetSubj SW on M.acWarehouse = SW.acSubject

                     LEFT JOIN tHE_SetSubj SS on M1.acSupplier = SS.acSubject

                     where m.anStockQty = 0

open xPoz

fetch from xPoz into @acWarehouse, @adDate

while @@fetch_status = 0

begin

                    exec pHE_MoveCreAll '1R00', '', @acWarehouse, @adDate, 2, '', @k output

 

                    insert into tHE_MoveItem (acKey, anNo, acIdent, acName, anQty, anPrice, anPriceCurrency, anStockPrice)

                    SELECT @k, ROW_NUMBER ( ) over (order by m.acIdent) , M.acIdent, m1.acName, 0, m.anvalue*-1, m.anvalue*-1, m.anvalue*-1

                    FROM #lHE_MovePrtActStockPrt1 M JOIN tHE_SetItem M1 on M.acIdent = M1.acIdent

                    LEFT JOIN tHE_SetItemCateg K on M1.acClassif = K.acClassif

                    LEFT JOIN tHE_SetItemCateg K2 on M1.acClassif2 = K2.acClassif

                    LEFT JOIN THE_SetItemPriceForWrh W on W.acIdent = M.acIdent AND W.acWarehouse = M.acWarehouse

                    LEFT JOIN tHE_SetSubj SW on M.acWarehouse = SW.acSubject

                    LEFT JOIN tHE_SetSubj SS on M1.acSupplier = SS.acSubject

                    where m.anStockQty = 0 and m.acWarehouse = @acWarehouse and m.datum = @adDate

 

fetch from xPoz into @acWarehouse, @adDate

end

close xPoz

deallocate xPoz