Poredjenje fin i roba po NC
if object_id('tempdb..#f') is not null
drop table #f
if object_id('tempdb..#r') is not null
drop table #r
declare @doc varchar (7)
set @doc = '18300%'
select left(replace(acDoc, '-', ''),5)+'0000'+right(replace(acDoc, '-', ''),4) as acKey, sum(anDebit-anCredit) as fIznos
into #f
from tHE_AcctTransItem
where acAcct = '1320'
and left(replace(acDoc, '-', ''),5)+'0000'+right(replace(acDoc, '-', ''),4) like @doc
group by left(replace(acDoc, '-', ''),5)+'0000'+right(replace(acDoc, '-', ''),4)
select g.acKey, round(sum(p.anQty*p.anStockPrice),2) as rIznos
into #r
from tHE_Move g
inner join tHE_MoveItem p on g.acKey = p.acKey
where g.acKey like @doc
group by g.acKey
select *, round(abs(fIznos)-abs(rIznos),1)
from #r r
inner join #f f on r.acKey = f.acKey
where abs(round(abs(fIznos)-abs(rIznos),1)) > 0