BALANTA SINTETICA MAMA PRECEDENTE
 select nvl(a.cont, b.cont) as cont,
case when Nvl(a.precdeb,0) > Nvl(a.preccred,0) then abs(Nvl(a.precdeb,0)-Nvl(a.preccred,0)) else 0 end + nvl(b.debit,0) as precdeb,
case when Nvl(a.precdeb,0) < Nvl(a.preccred,0) then abs(Nvl(a.precdeb,0)-Nvl(a.preccred,0)) else 0 end + nvl(b.credit,0) as preccred
from
(select cont, sum(precdeb) as precdeb, sum(preccred) as preccred
  from bal
 where an = 2008
   and luna = 1
   group by cont) a full join
(select cont, sum(ruldeb) as debit, sum(rulcred) as credit
  from bal
 where an = 2008
   and luna between 1 and 1
   group by cont) b on a.cont = b.cont;

BALANTA ANALITICA MAMA PRECEDENTE
 select nvl(a.cont, b.cont) as cont, nvl(a.acont, b.acont) as acont,
case when Nvl(a.precdeb,0) > Nvl(a.preccred,0) then abs(Nvl(a.precdeb,0)-Nvl(a.preccred,0)) else 0 end + nvl(b.debit,0) as precdeb,
case when Nvl(a.precdeb,0) < Nvl(a.preccred,0) then abs(Nvl(a.precdeb,0)-Nvl(a.preccred,0)) else 0 end + nvl(b.credit,0) as preccred
from
(select cont, acont, sum(precdeb) as precdeb, sum(preccred) as preccred
  from balana
 where an = 2008
   and luna = 1
   group by cont,acont) a full join
(select cont, acont, sum(ruldeb) as debit, sum(rulcred) as credit
  from balana
 where an = 2008
   and luna between 1 and 1
   group by cont,acont) b on a.cont = b.cont and a.acont = b.acont;


MAKE_TBALANTA - CONTURI SINTETICE SI ANALITICE DIN FIRMA MAMA
SET FILT TO INLIST(BNIVEL,6,7)