Download as xlsx, pdf, or txt
Download as xlsx, pdf, or txt
You are on page 1of 31

mto_aseg_por_tipo_y_cobert(vlast_day, a.

sseguro, 6)
select sum(decode(c.ctipgar,pctipgar,nvl(g.icapitalseg,0),0))
from --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
where c.cgarant = g.cgarant
and p.creaseg in (1,3)
and p.cgarant = g.cgarant
and p.cactivi = s.cactivi
and p.ccolect = s.ccolect
and p.ctipseg = s.ctipseg
and p.cmodali = s.cmodali
and p.cramo
= s.cramo
--SISMO
and g.cgarant in (2119,2013,2015,2109,2112,2110,2111,2008,2009,2010,2108,2107,2118,
2016,2012,2014,9135,9136,1905,1906,1907,1813,2412,1807,1808,1809,
1810,1811,1812,1903,1904,1939,1940,1966)
--and o.scontra = ces2.scontra
--and o.cgarant = g.cgarant
--and o.nmovimi = g.nmovimi
--and o.sseguro = g.sseguro
and g.nmovimi = (select max(x.nmovimi)
from movseguro x
where (x.cmotmov not in (700,200) and
x.cmotmov not between 300 and 399)
AND x.fcontab <= plast_day
AND x.sseguro = s.sseguro)
and g.sseguro = s.sseguro
and s.sseguro = psseguro;

SELECT Sum(DISTINCT x.icapmon)


FROM cesionesrea x
AND x.cgenera <> 7
AND (x.nmovigen,x.nriesgo) = (SELECT
FROM
AND
AND
AND
AND
WHERE
AND x.scontra = ce.scontra)
WHERE x.sseguro = a.sseguro

Max(nmovigen),Max(nriesgo)
cesionesrea xx
xx.cgenera <> 2
xx.cgenera <> 7
xx.FCONTAB <= vlast_day
xx.scontra = ce.scontra)
xx.sseguro = x.sseguro

mto_aseg_por_tipo(vlast_day, a.sseguro, 3)
prima_edificio_mo
SELECT Sum(Decode(c.ctipgar,3,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo

--AND
--AND
--AND
--AND
AND

o.scontra
o.cgarant
o.nmovimi
o.sseguro
g.nmovimi

AND g.sseguro
AND s.sseguro

=
=
=
=
=

ce.scontra
g.cgarant
g.nmovimi
g.sseguro
(SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
= s.sseguro
= a.sseguro

mto_aseg_scontra(vlast_day, a.sseguro, ce.scontra)


SELECT
FROM
WHERE
AND
AND
AND

Sum(DISTINCT x.icapmon)
cesionesrea x
x.cgenera <> 2
x.cgenera <> 7
x.fcontab <= vlast_day
(x.nmovigen,x.nriesgo) = (SELECT
FROM
WHERE
AND
AND
AND
AND
AND x.scontra = ce.scontra
AND x.sseguro = a.sseguro

Max(nmovigen),Max(nriesgo)
cesionesrea xx
xx.cgenera <> 2
xx.cgenera <> 7
xx.fcontab <= vlast_day
xx.scontra = x.scontra
xx.sseguro = x.sseguro)

SELECT Sum(Decode(c.ctipgar,4,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo

--AND
--AND
--AND
--AND
AND

o.scontra
o.cgarant
o.nmovimi
o.sseguro
g.nmovimi

AND g.sseguro
AND s.sseguro

SELECT
FROM
WHERE
AND
AND
AND

=
=
=
=
=

ce.scontra
g.cgarant
g.nmovimi
g.sseguro
(SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
= s.sseguro
= a.sseguro

Sum(DISTINCT x.icapmon)
cesionesrea x
x.cgenera <> 2
x.cgenera <> 7
x.fcontab <= vlast_day
(x.nmovigen,x.nriesgo) = (SELECT
FROM
WHERE
AND
AND
AND
AND
AND x.scontra = ce.scontra
AND x.sseguro = a.sseguro

Max(nmovigen),Max(nriesgo)
cesionesrea xx
xx.cgenera <> 2
xx.cgenera <> 7
xx.fcontab <= vlast_day
xx.scontra = x.scontra
xx.sseguro = x.sseguro)

SELECT Sum(Decode(c.ctipgar,6,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo

--AND
--AND
--AND
--AND
AND

o.scontra
o.cgarant
o.nmovimi
o.sseguro
g.nmovimi

AND g.sseguro
AND s.sseguro

SELECT
FROM
WHERE
AND
AND
AND

=
=
=
=
=

ce.scontra
g.cgarant
g.nmovimi
g.sseguro
(SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
= s.sseguro
= a.sseguro

Sum(DISTINCT x.icapmon)
cesionesrea x
x.cgenera <> 2
x.cgenera <> 7
x.fcontab <= vlast_day
(x.nmovigen,x.nriesgo) = (SELECT
FROM
WHERE
AND
AND
AND
AND
AND x.scontra = ce.scontra
AND x.sseguro = a.sseguro

Max(nmovigen),Max(nriesgo)
cesionesrea xx
xx.cgenera <> 2
xx.cgenera <> 7
xx.fcontab <= vlast_day
xx.scontra = x.scontra
xx.sseguro = x.sseguro)

SELECT Sum(Decode(c.ctipgar,3,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo

--AND
--AND
--AND
--AND
AND

o.scontra
o.cgarant
o.nmovimi
o.sseguro
g.nmovimi

AND g.sseguro
AND s.sseguro

SELECT
FROM
WHERE
AND
AND
AND

=
=
=
=
=

ce.scontra
g.cgarant
g.nmovimi
g.sseguro
(SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
= s.sseguro
= a.sseguro

Sum(DISTINCT x.icapmon)
cesionesrea x
x.cgenera <> 2
x.cgenera <> 7
x.fcontab <= vlast_day
(x.nmovigen,x.nriesgo) = (SELECT
FROM
WHERE
AND
AND
AND
AND
AND x.scontra = ce.scontra
AND x.sseguro = a.sseguro

Max(nmovigen),Max(nriesgo)
cesionesrea xx
xx.cgenera <> 2
xx.cgenera <> 7
xx.fcontab <= vlast_day
xx.scontra = x.scontra
xx.sseguro = x.sseguro)

SELECT Sum(Decode(c.ctipgar,4,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo

--AND
--AND
--AND
--AND
AND

o.scontra
o.cgarant
o.nmovimi
o.sseguro
g.nmovimi

AND g.sseguro
AND s.sseguro

SELECT
FROM
WHERE
AND
AND
AND

=
=
=
=
=

ce.scontra
g.cgarant
g.nmovimi
g.sseguro
(SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
= s.sseguro
= a.sseguro

Sum(DISTINCT x.icapmon)
cesionesrea x
x.cgenera <> 2
x.cgenera <> 7
x.fcontab <= vlast_day
(x.nmovigen,x.nriesgo) = (SELECT
FROM
WHERE
AND
AND
AND
AND
AND x.scontra = ce.scontra
AND x.sseguro = a.sseguro

Max(nmovigen),Max(nriesgo)
cesionesrea xx
xx.cgenera <> 2
xx.cgenera <> 7
xx.fcontab <= vlast_day
xx.scontra = x.scontra
xx.sseguro = x.sseguro)

SELECT Sum(Decode(c.ctipgar,6,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo

--AND
--AND
--AND
--AND
AND

o.scontra
o.cgarant
o.nmovimi
o.sseguro
g.nmovimi

AND g.sseguro
AND s.sseguro

SELECT
FROM
WHERE
AND
AND
AND

=
=
=
=
=

ce.scontra
g.cgarant
g.nmovimi
g.sseguro
(SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
= s.sseguro
= a.sseguro

Sum(DISTINCT x.icapmon)
cesionesrea x
x.cgenera <> 2
x.cgenera <> 7
x.fcontab <= vlast_day
(x.nmovigen,x.nriesgo) = (SELECT
FROM
WHERE
AND
AND
AND
AND
AND x.scontra = ce.scontra
AND x.sseguro = a.sseguro

Max(nmovigen),Max(nriesgo)
cesionesrea xx
xx.cgenera <> 2
xx.cgenera <> 7
xx.fcontab <= vlast_day
xx.scontra = x.scontra
xx.sseguro = x.sseguro)

cum_imto_edif_ced_cnt_t1
SELECT Sum(Decode(c.ctipgar,6,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo

--AND
--AND
--AND
--AND
AND

o.scontra
o.cgarant
o.nmovimi
o.sseguro
g.nmovimi

=
=
=
=
=

AND g.sseguro
AND s.sseguro
--AND p.cpargar

ce.scontra
g.cgarant
g.nmovimi
g.sseguro
(SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
= s.sseguro
= a.sseguro
= 'SUMA_CAPITAL'

--AND p.cvalpar

= 1

SELECT Sum(Decode(c.ctipgar,3,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo

--AND
--AND
--AND
--AND
AND

o.scontra
o.cgarant
o.nmovimi
o.sseguro
g.nmovimi

=
=
=
=
=

AND g.sseguro
AND s.sseguro
--AND p.cpargar

ce.scontra
g.cgarant
g.nmovimi
g.sseguro
(SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
= s.sseguro
= a.sseguro
= 'SUMA_CAPITAL'

--AND p.cvalpar

= 1

SELECT Sum(Decode(c.ctipgar,3,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo

--AND
--AND
--AND
--AND
AND

o.scontra
o.cgarant
o.nmovimi
o.sseguro
g.nmovimi

=
=
=
=
=

AND g.sseguro
AND s.sseguro
--AND p.cpargar

ce.scontra
g.cgarant
g.nmovimi
g.sseguro
(SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
= s.sseguro
= a.sseguro
= 'SUMA_CAPITAL'

--AND p.cvalpar

= 1

SELECT Sum(Decode(c.ctipgar,3,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo
--AND o.scontra = ce.scontra
--AND o.cgarant = g.cgarant
--AND o.nmovimi = g.nmovimi
--AND o.sseguro = g.sseguro
AND g.nmovimi = (SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
--AND p.cpargar = 'SUMA_CAPITAL'
--AND p.cvalpar = 1
AND g.sseguro = s.sseguro
AND s.sseguro = a.sseguro

SELECT Sum(Decode(c.ctipgar,3,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo
--AND o.scontra = ce.scontra
--AND o.cgarant = g.cgarant
--AND o.nmovimi = g.nmovimi
--AND o.sseguro = g.sseguro
AND g.nmovimi = (SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
--AND p.cpargar = 'SUMA_CAPITAL'
--AND p.cvalpar = 1
AND g.sseguro = s.sseguro
AND s.sseguro = a.sseguro

SELECT Sum(Decode(c.ctipgar,4,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo
--AND o.scontra = ce.scontra
--AND o.cgarant = g.cgarant
--AND o.nmovimi = g.nmovimi
--AND o.sseguro = g.sseguro
AND g.nmovimi = (SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
--AND p.cpargar = 'SUMA_CAPITAL'
--AND p.cvalpar = 1
AND g.sseguro = s.sseguro
AND s.sseguro = a.sseguro

SELECT Sum(Decode(c.ctipgar,4,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo
--AND o.scontra = ce.scontra
--AND o.cgarant = g.cgarant
--AND o.nmovimi = g.nmovimi
--AND o.sseguro = g.sseguro
AND g.nmovimi = (SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
--AND p.cpargar = 'SUMA_CAPITAL'
--AND p.cvalpar = 1
AND g.sseguro = s.sseguro
AND s.sseguro = a.sseguro

SELECT Sum(Decode(c.ctipgar,4,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo
--AND o.scontra = ce.scontra
--AND o.cgarant = g.cgarant
--AND o.nmovimi = g.nmovimi
--AND o.sseguro = g.sseguro
AND g.nmovimi = (SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
--AND p.cpargar = 'SUMA_CAPITAL'
--AND p.cvalpar = 1
AND g.sseguro = s.sseguro
AND s.sseguro = a.sseguro

SELECT Sum(Decode(c.ctipgar,4,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo
--AND o.scontra = ce.scontra
--AND o.cgarant = g.cgarant
--AND o.nmovimi = g.nmovimi
--AND o.sseguro = g.sseguro
AND g.nmovimi = (SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
--AND p.cpargar = 'SUMA_CAPITAL'
--AND p.cvalpar = 1
AND g.sseguro = s.sseguro
AND s.sseguro = a.sseguro

SELECT Sum(Decode(c.ctipgar,6,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo
--AND o.scontra = ce.scontra
--AND o.cgarant = g.cgarant
--AND o.nmovimi = g.nmovimi
--AND o.sseguro = g.sseguro
AND g.nmovimi = (SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
--AND p.cpargar = 'SUMA_CAPITAL'
--AND p.cvalpar = 1
AND g.sseguro = s.sseguro
AND s.sseguro = a.sseguro

SELECT Sum(Decode(c.ctipgar,6,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo
--AND o.scontra = ce.scontra
--AND o.cgarant = g.cgarant
--AND o.nmovimi = g.nmovimi
--AND o.sseguro = g.sseguro
AND g.nmovimi = (SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
--AND p.cpargar = 'SUMA_CAPITAL'
--AND p.cvalpar = 1
AND g.sseguro = s.sseguro
AND s.sseguro = a.sseguro)*
valor_mo_uf(a.moneda, pfcierre

SELECT Sum(Decode(c.ctipgar,6,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo
--AND o.scontra = ce.scontra
--AND o.cgarant = g.cgarant
--AND o.nmovimi = g.nmovimi
--AND o.sseguro = g.sseguro
AND g.nmovimi = (SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
--AND p.cpargar = 'SUMA_CAPITAL'
--AND p.cvalpar = 1
AND g.sseguro = s.sseguro
AND s.sseguro = a.sseguro

SELECT Sum(Decode(c.ctipgar,6,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo
--AND o.scontra = ce.scontra
--AND o.cgarant = g.cgarant
--AND o.nmovimi = g.nmovimi
--AND o.sseguro = g.sseguro
AND g.nmovimi = (SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
--AND p.cpargar = 'SUMA_CAPITAL'
--AND p.cvalpar = 1
AND g.sseguro = s.sseguro
AND s.sseguro = a.sseguro

SELECT Sum(Decode(c.ctipgar,6,Nvl(g.icapitalseg,0),0))
FROM --garancontra o,
codigaran c, garanpro p, garanseg g, seguros s
WHERE c.cgarant = g.cgarant
AND p.creaseg IN (1,3)
AND p.cgarant = g.cgarant
AND p.cactivi = s.cactivi
AND p.ccolect = s.ccolect
AND p.ctipseg = s.ctipseg
AND p.cmodali = s.cmodali
AND p.cramo
= s.cramo
--AND o.scontra = ce.scontra
--AND o.cgarant = g.cgarant
--AND o.nmovimi = g.nmovimi
--AND o.sseguro = g.sseguro
AND g.nmovimi = (SELECT Max(x.nmovimi)
FROM movseguro x
WHERE (x.cmotmov not IN (700,200) AND
x.cmotmov not between 300 AND 399)
AND x.fcontab <= vlast_day
AND x.sseguro = s.sseguro)
--AND p.cpargar = 'SUMA_CAPITAL'
--AND p.cvalpar = 1
AND g.sseguro = s.sseguro
AND s.sseguro = a.sseguro

You might also like