--Tabla SB36 delete from TBAN05FINAL; insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '111', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '112', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '113', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '114', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '115', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '116', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '117', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '118', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '119', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '12', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '13', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '14', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '211', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '212', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '213', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '214', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '215', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '311', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '3121', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '3122', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '313', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '314', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '315', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '3152', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '316', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '317', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '3172', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '318', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '319', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '32', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '3211', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '411', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '412', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '4131', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '4132', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '4133', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '4134', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '414', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '415', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '416', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '511', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '512', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '513', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '514', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '515', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '516', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '517', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '519', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '5191', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '6111', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '6112', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '6113', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '6121', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '6122', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '6123', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '711', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '712', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '713', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '714', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '716', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '719', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '8111', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '8112', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '8113', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '8114', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '8121', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '8122', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '8123', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '8124', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '8125', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '8126', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '8127', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '822', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '823', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '824', null); insert into TBAN05FINAL (FECHA, CODIGO_BANCO, CODIGO_CUENTA, MONTO_INICIAL) values (null, null, '825', null); delete from TSENTENCIACONSULTA where CSENTENCIACONSULTA='BA04_BASE_1'; insert into TSENTENCIACONSULTA (CSENTENCIACONSULTA, NOMBRE, SENTENCIA) values ('BA04_BASE_1', 'LLENADO TABLA INTERMEDIA BA04', '/*Para esta tabla BAN es necesario parametrizar la tabla TPRODUCTOTASAS de acuerdo a las tablas SB26 y SB33 En el caso de la tabla SB26 se quemara 01 si los rangos no corresponden. En el caso de la tabla SB33 se quemara XX si los rangos no corresponden. */ select :fecha FECHA, decode(substr(cd.codigocontable,0,1),''1'',''A'',''P'') TIPO_TASA, pc.cdestinofondos ACTIVIDAD, case when pt.plazominimo=0 then ''01'' when pt.plazominimo>=1 and pt.plazomaximo<=30 then ''02'' when pt.plazominimo>=31 and pt.plazomaximo<=60 then ''03'' when pt.plazominimo>=61 and pt.plazomaximo<=90 then ''04'' when pt.plazominimo>=91 and pt.plazomaximo<=180 then ''05'' when pt.plazominimo>=181 and pt.plazomaximo<=270 then ''06'' when pt.plazominimo>=271 and pt.plazomaximo<=360 then ''07'' when pt.plazominimo>=361 and pt.plazomaximo<=1080 then ''08'' when pt.plazominimo>=1081 and pt.plazomaximo<=1800 then ''09'' when pt.plazominimo>=1801 and pt.plazomaximo<=3600 then ''10'' when pt.plazominimo>3600 then ''11'' else ''01'' end RANGOTIEMPO, ''XX'' RANGOMONTO, tr.tasa+pt.margen TASA from tproductocolocaciones pc, tproductocategoriatasas pct, tcategoriasdetalle cd, tproductotasas pt, ttasasreferenciales tr where pc.cpersona_compania=pct.cpersona_compania and pc.csubsistema=pct.csubsistema and pc.cgrupoproducto=pct.cgrupoproducto and pc.cproducto=pct.cproducto and pc.fhasta=fncfhasta and pc.fhasta=pct.fhasta and cd.categoria=pct.categoria and cd.cpersona_compania=pct.cpersona_compania and cd.cgrupobalance=pct.cgrupobalance and pt.cpersona_compania=pct.cpersona_compania and pt.csubsistema=pct.csubsistema and pt.cgrupoproducto=pct.cgrupoproducto and pt.cproducto=pct.cproducto and pt.categoria=pct.categoria and pt.cgrupobalance=pct.cgrupobalance and pt.cmoneda=pct.cmoneda and pt.fhasta=pct.fhasta and tr.cpersona_compania=pct.cpersona_compania and tr.ctasareferencial=pt.ctasareferencial and tr.cmoneda=pt.cmoneda and tr.fhasta=pt.fhasta union all select :fecha FECHA, decode(substr(cd.codigocontable,0,1),''1'',''A'',''P'') TIPO_TASA, ''2206'' ACTIVIDAD, case when pt.plazominimo=0 then ''01'' when pt.plazominimo>=1 and pt.plazomaximo<=30 then ''02'' when pt.plazominimo>=31 and pt.plazomaximo<=60 then ''03'' when pt.plazominimo>=61 and pt.plazomaximo<=90 then ''04'' when pt.plazominimo>=91 and pt.plazomaximo<=180 then ''05'' when pt.plazominimo>=181 and pt.plazomaximo<=270 then ''06'' when pt.plazominimo>=271 and pt.plazomaximo<=360 then ''07'' when pt.plazominimo>=361 and pt.plazomaximo<=1080 then ''08'' when pt.plazominimo>=1081 and pt.plazomaximo<=1800 then ''09'' when pt.plazominimo>=1801 and pt.plazomaximo<=3600 then ''10'' when pt.plazominimo>3600 then ''11'' else ''01'' end RANGOTIEMPO, case when pt.montominimo>=10000 and pt.montomaximo<=19999 then ''38'' when pt.montominimo>=20000 and pt.montomaximo<=49999 then ''39'' when pt.montominimo>=50000 and pt.montomaximo<=99999 then ''40'' when pt.montominimo>=100000 and pt.montomaximo<=249999 then ''41'' when pt.montominimo>=250000 and pt.montomaximo<=499999 then ''42'' when pt.montominimo>=500000 then ''43'' else ''XX'' end RANGOMONTO, tr.tasa+pt.margen TASA from tproductocaptacionesplazo pcp, tproductocategoriatasas pct, tcategoriasdetalle cd, tproductotasas pt, ttasasreferenciales tr where pcp.cpersona_compania=pct.cpersona_compania and pcp.csubsistema=pct.csubsistema and pcp.cgrupoproducto=pct.cgrupoproducto and pcp.cproducto=pct.cproducto and pcp.fhasta=:fhasta and pcp.fhasta=pct.fhasta and cd.categoria=pct.categoria and cd.cpersona_compania=pct.cpersona_compania and cd.cgrupobalance=pct.cgrupobalance and pt.cpersona_compania=pct.cpersona_compania and pt.csubsistema=pct.csubsistema and pt.cgrupoproducto=pct.cgrupoproducto and pt.cproducto=pct.cproducto and pt.categoria=pct.categoria and pt.cgrupobalance=pct.cgrupobalance and pt.cmoneda=pct.cmoneda and pt.fhasta=pct.fhasta and tr.cpersona_compania=pct.cpersona_compania and tr.ctasareferencial=pt.ctasareferencial and tr.cmoneda=pt.cmoneda and tr.fhasta=pt.fhasta'); delete from TSENTENCIACONSULTA where CSENTENCIACONSULTA='BA05_BASE_1'; insert into TSENTENCIACONSULTA (CSENTENCIACONSULTA, NOMBRE, SENTENCIA) values ('BA05_BASE_1', 'LLENADO TABLA INTERMEDIA BA05', 'select :fecha FECHA, ''153'' BANCO, aux.codigocontable || substr(''000000'', 1, 6-length(aux.codigocontable)) codigo_cuenta, (select sum(s.saldomonedacuenta) from tsaldos s where s.codigocontable=aux.codigocontable and s.principal=1 and s.fhasta=aux.fhasta and s.cpersona_compania=aux.cpersona_compania and :fecha between s.fcontabledesde and s.fcontablehasta group by s.codigocontable) saldo_inicial from (select cc.codigocontable codigocontable, cc.fhasta fhasta, cc.cpersona_compania cpersona_compania from tban05final bf, tcatalogocuentas cc where cc.codigocontable=bf.codigo_cuenta and cc.fhasta=:fhasta and cc.cpersona_compania=''2'') aux'); delete from TSENTENCIACONSULTA where CSENTENCIACONSULTA='BA06_BASE_1'; insert into TSENTENCIACONSULTA (CSENTENCIACONSULTA, NOMBRE, SENTENCIA) values ('BA06_BASE_1', 'LLENADO TABLA INTERMEDIA BA06', 'select :fecha FECHA, ''153'' BANCO, aux.codigocontable||substr(''000000'', 1, 6-length(aux.codigocontable)) CODIGOCONTABLE, decode((select pd.cpais from tpersonadirecciones pd where pd.fhasta=aux.fhasta and pd.cpersona=aux.cpersona and pd.direccionprincipal=1), ''PA'', ''L'' , ''E'') LOCALIDAD, case when (select pd.cpais from tpersonadirecciones pd where pd.fhasta=aux.fhasta and pd.cpersona=aux.cpersona and pd.direccionprincipal=1)=''PA'' then (select pd.cprovincia from tpersonadirecciones pd where pd.fhasta=aux.fhasta and pd.cpersona=aux.cpersona and pd.direccionprincipal=1) else (select pi.codigopais from tpersonadirecciones pd, tpaisesid pi where pd.fhasta=aux.fhasta and pd.cpersona=aux.cpersona and pd.direccionprincipal=1 and pi.cpais=pd.cpais) end RESIDENCIA, decode ( (select cci.codigocalificacion from tcalificacioncreditoid cci, tcuentacalificacion cc2 where cc2.ccalificacioncredito=cci.ccalificacioncredito and cc2.ccuenta=aux.ccuenta and cc2.cpersona_compania=aux.cpersona_compania and cc2.fhasta=aux.fhasta), null, (select case when ccu.fvencimiento-:fecha between 0 and 30 then ''01'' when ccu.fvencimiento-:fecha between 31 and 60 then ''02'' when ccu.fvencimiento-:fecha between 61 and 90 then ''03'' when ccu.fvencimiento-:fecha between 91 and 360 then ''04'' when ccu.fvencimiento-:fecha > 360 then ''05'' end from tcuentacuotas ccu where ccu.ccuenta=aux.ccuenta and ccu.fpago is null and ccu.fhasta=aux.fhasta and ccu.cpersona_compania=aux.cpersona_compania and ccu.fvencimiento=(select min(ccu2.fvencimiento) from tcuentacuotas ccu2 where ccu2.ccuenta=ccu.ccuenta and ccu2.fpago is null and ccu2.fhasta=ccu.fhasta and ccu.cpersona_compania=ccu2.cpersona_compania)), (select cci.codigocalificacion from tcalificacioncreditoid cci, tcuentacalificacion cc2 where cc2.ccalificacioncredito=cci.ccalificacioncredito and cc2.ccuenta=aux.ccuenta and cc2.cpersona_compania=aux.cpersona_compania and cc2.fhasta=aux.fhasta)) CLASIFPRESTAMO, ''01'' FACILIDAD, --no aplican los otros campos (select decode(sum(s.saldomonedacuenta),null,0,sum(s.saldomonedacuenta)) from tsaldos s where s.codigocontable=aux.codigocontable and s.fhasta=aux.fhasta and s.principal=''1'' and aux.ccuenta=s.ccuenta and aux.cpersona_compania=s.cpersona_compania and s.fvencimiento-:fecha > 0 group by aux.ccuenta) MONTO, decode( (select cc2.porcentajecalificacion from tcuentacalificacion cc2 where cc2.ccuenta=aux.ccuenta and cc2.fhasta=aux.fhasta and cc2.cpersona_compania=aux.cpersona_compania), null, (select case when ccu.fvencimiento-:fecha between 31 and 60 then 2 when ccu.fvencimiento-:fecha between 61 and 90 then 15 when ccu.fvencimiento-:fecha between 91 and 360 then 50 when ccu.fvencimiento-:fecha > 360 then 100 end from tcuentacuotas ccu where ccu.ccuenta=aux.ccuenta and ccu.fpago is null and ccu.fhasta=aux.fhasta and ccu.cpersona_compania=aux.cpersona_compania and ccu.fvencimiento=(select min(ccu2.fvencimiento) from tcuentacuotas ccu2 where ccu2.ccuenta=ccu.ccuenta and ccu2.fpago is null and ccu2.fhasta=ccu.fhasta and ccu.cpersona_compania=ccu2.cpersona_compania)), (select cc2.porcentajecalificacion from tcuentacalificacion cc2 where cc2.ccuenta=aux.ccuenta and cc2.fhasta=aux.fhasta and cc2.cpersona_compania=aux.cpersona_compania)) PROVISION, --se calcula internamente (select decode(sum(s.saldomonedacuenta),null,0,sum(s.saldomonedacuenta)) from tsaldos s where s.codigocontable=aux.codigocontable and s.fhasta=aux.fhasta and s.principal=''1'' and aux.ccuenta=s.ccuenta and aux.cpersona_compania=s.cpersona_compania and s.fvencimiento-:fecha between 1 and 30 group by aux.ccuenta) MTO_XV30D, (select decode(sum(s.saldomonedacuenta),null,0,sum(s.saldomonedacuenta)) from tsaldos s where s.codigocontable=aux.codigocontable and s.fhasta=aux.fhasta and s.principal=''1'' and aux.ccuenta=s.ccuenta and aux.cpersona_compania=s.cpersona_compania and s.fvencimiento-:fecha between 31 and 60 group by aux.ccuenta) MTO_XV60D, (select decode(sum(s.saldomonedacuenta),null,0,sum(s.saldomonedacuenta)) from tsaldos s where s.codigocontable=aux.codigocontable and s.fhasta=aux.fhasta and s.principal=''1'' and aux.ccuenta=s.ccuenta and aux.cpersona_compania=s.cpersona_compania and s.fvencimiento-:fecha between 61 and 90 group by aux.ccuenta) MTO_XV90D, (select decode(sum(s.saldomonedacuenta),null,0,sum(s.saldomonedacuenta)) from tsaldos s where s.codigocontable=aux.codigocontable and s.fhasta=aux.fhasta and s.principal=''1'' and aux.ccuenta=s.ccuenta and aux.cpersona_compania=s.cpersona_compania and s.fvencimiento-:fecha between 91 and 180 group by aux.ccuenta) MTO_XV180D, (select decode(sum(s.saldomonedacuenta),null,0,sum(s.saldomonedacuenta)) from tsaldos s where s.codigocontable=aux.codigocontable and s.fhasta=aux.fhasta and s.principal=''1'' and aux.ccuenta=s.ccuenta and aux.cpersona_compania=s.cpersona_compania and s.fvencimiento-:fecha between 181 and 360 group by aux.ccuenta) MTO_XV1A, (select decode(sum(s.saldomonedacuenta),null,0,sum(s.saldomonedacuenta)) from tsaldos s where s.codigocontable=aux.codigocontable and s.fhasta=aux.fhasta and s.principal=''1'' and aux.ccuenta=s.ccuenta and aux.cpersona_compania=s.cpersona_compania and s.fvencimiento-:fecha > 360 group by aux.ccuenta) MTO_XVM1A, (select p.identificacion from tpersona p where p.cpersona=aux.cpersona and p.fhasta=aux.fhasta) ID_CLIENTE, (select p.nombrelegal from tpersona p where p.cpersona=aux.cpersona and p.fhasta=aux.fhasta) NOMBRE_CLIENTE, (select p.identificacion from tpersonavinculaciones pv, tpersona p where pv.cpersona=aux.cpersona and pv.cpersona_vinculada=p.cpersona and pv.fhasta=aux.fhasta and p.fhasta=aux.fhasta and p.mastergrupo=1) ID_GRUPOECONOMICO, (select p.nombrelegal from tpersonavinculaciones pv, tpersona p where pv.cpersona=aux.cpersona and pv.cpersona_vinculada=p.cpersona and pv.fhasta=aux.fhasta and p.fhasta=aux.fhasta and p.mastergrupo=1) NOMBRE_GRUPOECONOMICO from (select cc.codigocontable CODIGOCONTABLE, c.ccuenta CCUENTA, c.cpersona_cliente CPERSONA, :fhasta FHASTA, 2 CPERSONA_COMPANIA FROM tsaldos s, tcatalogocuentas cc, tcuenta c WHERE length(s.cgrupobalance)=2 and substr(s.cgrupobalance,1,1) IN (''6'', ''7'') and s.fhasta=fncfhasta and s.cpersona_compania=2 and s.principal=1 and cc.fhasta=s.fhasta and cc.cpersona_compania=s.cpersona_compania and cc.aplicaatomo=1 and cc.codigocontable=s.codigocontable and c.ccuenta=s.ccuenta and c.cpersona_compania=s.cpersona_compania and c.fhasta=s.fhasta and s.fvencimiento>:fecha and s.saldomonedacuenta>0 group by c.ccuenta, cc.codigocontable, c.cpersona_cliente) aux');