Professional Documents
Culture Documents
max(nom_segmento) as nom_segmento,
max(nom_sub_segmento) as nom_sub_segmento
from E_DW_VIEWS.V_FCT_SEGMENTO_MERCADO
where nro_documento ne '.' and EXTRACT (YEAR FROM
Fch_SBS) = 2019 AND EXTRACT (MONTH FROM Fch_SBS) = 11
group by fch_Sbs, cod_tipo_documento,nro_documento) b
on a.tipdoc=CAST(b.cod_tipo_documento AS INTEGER) and
a.coddoc=b.nro_documento
and EXTRACT (YEAR FROM Fch_SBS) = 2019 AND EXTRACT (MONTH FROM
Fch_SBS) = 11
where a.codmes >='201911' and a.codmes<='201911' and
a.codempresa in ('00001','00006','00004','00002','00055','00022',
'00142','00082','00073','00145','00072','00129')
group by a.codmes, a.codempresa, b.nom_segmento, b.nom_sub_segmento,
a.filrefcli, a.fildias, a.cartera, a.rangoscp
UNION ALL
max(nom_segmento) as nom_segmento,
max(nom_sub_segmento) as nom_sub_segmento
from E_DW_VIEWS.V_FCT_SEGMENTO_MERCADO
where nro_documento ne '.' and EXTRACT (YEAR FROM
Fch_SBS) = 2019 AND EXTRACT (MONTH FROM Fch_SBS) = 11
group by fch_Sbs,cod_tipo_documento,nro_documento) b
on a.tipdoc=CAST(b.cod_tipo_documento AS INTEGER) and
a.coddoc=b.nro_documento
and EXTRACT (YEAR FROM Fch_SBS) = 2019 AND EXTRACT (MONTH FROM
Fch_SBS) = 11
where a.codmes >='201911' and a.codmes<='201911' and
a.codempresa in ('00072','00004','00129')
group by a.codmes, a.codempresa, b.nom_segmento, b.nom_sub_segmento,
a.filrefcli, a.fildias, a.cartera, a.rangoscp
)with DATA
PRIMARY INDEX (CODMES, CODEMPRESA, NOM_SEGMENTO, NOM_SUB_SEGMENTO, FILREFCLI,
FILDIAS, CARTERA, RANGOSCBUROPER)
ON COMMIT PRESERVE ROWS
CREATE SET VOLATILE TABLE TB_JM_RESUMEN_FINAL AS
(
select a.codmes, a.nom_segmento, a.nom_sub_segmento, a.codempresa, a.filrefcli,
a.fildias, a.cartera, a.rangoscburoper,
CASE WHEN b.nbrempresa is null THEN 'Scotibank + Crediscotia + Cencosud'
ELSE b.nbrempresa END AS nbrempresa,
sum(cuenta) as cuenta, sum(a.mtosaldo) as mtosaldo, sum(a.linea) as
linea
from TB_JM_RESUMEN a
left join E_DM_CR_SCORING.lcl_codempresarcc b
on a.codempresa = b.codempresa
group by a.codmes, a.nom_segmento, a.nom_sub_segmento, a.codempresa, a.filrefcli,
a.fildias, a.cartera, a.rangoscburoper,nbrempresa
) with DATA
PRIMARY INDEX (CODMES, NOM_SEGMENTO, NOM_SUB_SEGMENTO, CODEMPRESA, filrefcli,
fildias, CARTERA, RANGOSCBUROPER)
ON COMMIT PRESERVE ROWS