Objedini inventuru

select acIdent, sum(anQty) as anQty
into #i
from tHE_MoveItem
where acKey in (’149ATC0000001′,’149ATC0000002′)
group by acIdent

alter table #i
add acKey char (13) default ’149ATC0000003′ not null,
anNo int identity (1,1) not null

insert into tHE_MoveItem (anQty, acKey, anNo, acIdent, acName, acUm, anPrice, anRTPrice, anSalePrice,
acVATCode, anVAT, anStockPrice, anInRTPrice, anInSalePrice,
acVATCodeTR, anVATIn)
select t.anQty, t.acKey, t.anNo, m.acIdent, m.acName, m.acUM, case when c.anRTPrice is null then m.anRTPrice else c.anRTPrice end, case when c.anRTPrice is null then m.anRTPrice else c.anRTPrice end, case when c.anSalePrice is null then m.anSalePrice else c.anSalePrice end,
m.acVATCode, m.anVAT, m.anBuyPrice, case when c.anRTPrice is null then m.anRTPrice else c.anRTPrice end, case when c.anSalePrice is null then m.anSalePrice else c.anSalePrice end,
m.acVATCode, m.anVAT
from tHE_SetItem m
inner join #i t on m.acIdent = t.acIdent
left join tHE_SetItemPriceForWrh c on m.acIdent = c.acIdent and c.acWarehouse = ‘Skladiste’