You are on page 1of 3

--- PROSPECTOS --

TRUNCATE TABLE TEMP_PRODUCTO_DPF;


DROP TABLE TEMP_PRODUCTO_DPF;
COMMIT;

CREATE TABLE TEMP_PRODUCTO_DPF AS

select cod_producto from sdbx_inco.dim_productos where familia = ('CAPTACIONES -


AHORRO PLAZO')
and cod_producto not in (1251);

TRUNCATE TABLE PROSPECTOS_DPF_UL6M;


DROP TABLE PROSPECTOS_DPF_UL6M;
COMMIT;

CREATE TABLE PROSPECTOS_DPF_UL6M AS

SELECT A.CO_CLIENTE, MAX(A.FE_PROCESO) AS FE_PROCESO


FROM HD_EGD A
WHERE A.fe_proceso < '14/05/2018' AND A.fe_proceso >= '01/12/2017'
AND MO_SALD_ACTU_MN>= 10000
AND A.CO_PRODUCTO IN (select cod_producto from TEMP_PRODUCTO_DPF)
GROUP BY A.CO_CLIENTE

TRUNCATE TABLE PROSPECTOS_PROD_HOY;


DROP TABLE PROSPECTOS_PROD_HOY;
COMMIT;

CREATE TABLE PROSPECTOS_PROD_HOY AS

SELECT DISTINCT CASE WHEN B.COD_PRODUCTO IS NOT NULL THEN 'DPF'


WHEN B.COD_PRODUCTO IS NULL THEN 'CTS O AHORRO' END AS FLG_PROD,
A.CO_CLIENTE, A.FE_PROCESO,A.co_sucu_anal, D.CANAL
FROM HD_EGD A
INNER JOIN PROSPECTOS_DPF_UL6M BAS ON A.CO_CLIENTE = BAS.CO_CLIENTE
LEFT JOIN TEMP_PRODUCTO_DPF B ON A.CO_PRODUCTO = B.COD_PRODUCTO
LEFT JOIN sdbx_inco.DIM_FUNCIONARIOs D ON A.CO_ANALISTA=D.cod_funcionario
WHERE A.fe_proceso = '14/05/2018'
AND (D.CANAL NOT IN ('ASESOR DE NEGOCIOS','EJECUTIVO DE CUENTAS PASIVAS','BANCA
PRIVADA') OR D.CANAL IS NULL);

SELECT COUNT(*) FROM PROSPECTOS_PROD_HOY WHERE CANAL IS NULL


SELECT * FROM HD_EGD WHERE fe_proceso = '01/02/2018' AND CO_CLIENTE = '5230039'

SELECT * FROM PROSPECTOS_DPF_UL6M WHERE CO_CLIENTE = '5230039'


SELECT CO_CLIENTE,COUNT(*) FROM PROSPECTOS_PROD_HOY GROUP BY CO_CLIENTE HAVING
COUNT(*)> 2
SELECT * FROM PROSPECTOS_PROD_HOY WHERE CO_CLIENTE = '2495717'

TRUNCATE TABLE PROSPECTOS_BASE;


DROP TABLE PROSPECTOS_BASE;
COMMIT;

CREATE TABLE PROSPECTOS_BASE AS

SELECT A.*,
CASE WHEN B.CO_CLIENTE IS NOT NULL THEN 'VIGENTE' ELSE 'NO VIGENTE' END AS
FLG_VIG_DPF,
CASE WHEN C.CO_CLIENTE IS NOT NULL THEN 'VIGENTE' ELSE 'NO VIGENTE' END AS
FLG_VIG_CTS_AHO,
--B.co_sucu_anal AS SUCU_ANA_HOY_DPF,
C.co_sucu_anal AS SUCU_ANA_HOY_CTS_AHO,
B.CANAL AS CANAL_DPF,C.CANAL AS CANAL_CTS_AHO,C.FE_PROCESO AS
FE_PROCESO_ACTUAL
FROM PROSPECTOS_DPF_UL6M A
LEFT JOIN PROSPECTOS_PROD_HOY B ON A.CO_CLIENTE = B.CO_CLIENTE AND b.FLG_PROD =
'DPF'
LEFT JOIN PROSPECTOS_PROD_HOY c ON A.CO_CLIENTE = c.CO_CLIENTE AND c.FLG_PROD =
'CTS O AHORRO';

SELECT * FROM PROSPECTOS_PROD_HOY WHERE co_cliente = '4939154'

SELECT CO_CLIENTE,COUNT(*) FROM PROSPECTOS_BASE GROUP BY CO_CLIENTE HAVING


COUNT(*) > 1

SELECT * FROM PROSPECTOS_BASE WHERE CO_CLIENTE = '2832990'

SELECT DISTINCT C.* FROM HD_EGD A


INNER JOIN PROSPECTOS_PROD_HOY c ON A.CO_CLIENTE = c.CO_CLIENTE AND c.FLG_PROD =
'CTS O AHORRO'
WHERE A.fe_proceso = '29/01/2018' AND A.CO_CLIENTE = '4939154' AND C.co_sucu_anal
IN (617,12)

-- VERIFICACION

SELECT * FROM PROSPECTOS_BASE


WHERE FLG_VIG_DPF = 'NO VIGENTE' AND FLG_VIG_CTS_AHO = 'VIGENTE'
--AND (COD_ANA_HOY_DPF=463 OR COD_ANA_HOY_CTS_AHO = 463)
AND co_cliente = '4939154'

-- VALIDACION

SELECT CO_CLIENTE,COUNT(*) FROM PROSPECTOS_BASE


WHERE FLG_VIG_DPF = 'NO VIGENTE' AND FLG_VIG_CTS_AHO = 'VIGENTE'
--AND (COD_ANA_HOY_DPF=463 OR COD_ANA_HOY_CTS_AHO = 463)
--AND co_cliente = '4462530'
AND SUCU_ANA_HOY_CTS_AHO=463
GROUP BY CO_CLIENTE
HAVING COUNT(*) > 1

-- BASE FINAL

SELECT * FROM PROSPECTOS_BASE


WHERE FLG_VIG_DPF = 'NO VIGENTE' AND FLG_VIG_CTS_AHO = 'VIGENTE'
AND SUCU_ANA_HOY_CTS_AHO=463

Related Interests