Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as SQL by registered user vvillacorta ( 1 year ago )
TERADATA

    -------------------------  LÓGICA CAIDAS POR FALTA DE CONTACTO (RUCS) - ULTIMOS 3 MESES  (11K)

SELECT B.PERIODO_VAL,

       B.NOMBRE_DSC CAMPANHA,

     C.NUM_RUC_CD,

     B.BANCA_DSC,

     J.TIPO_CAMPANHA_DSC,

     A.MOTIVONOACTIVO_DSC

FROM E_DW_VIEWS.V_VPC_NEG_EMPRESAS_CAMP_VIG A

JOIN E_DW_VIEWS.V_VPC_NEG_CAMPANHAS_INST_VIG B ON B.CAMPANHA_INSTANCIA_ID=A.CAMPANHA_INSTANCIA_ID

JOIN E_DW_VIEWS.V_VPC_NEG_EMPRESAS_VIG C ON C.EMPRESA_ID=A.EMPRESA_ID

LEFT JOIN E_DW_VIEWS.V_VPC_NEG_CAMPANHAS_VIG J ON J.CAMPANHA_ID=B.CAMPANHA_ID

WHERE B.PERIODO_VAL IN ('202306', '202305', '202304')

AND A.MOTIVONOACTIVO_DSC LIKE '%CONTACTO%'

AND C.NUM_RUC_CD <> '.'

AND C.NUM_RUC_CD NOT LIKE ''

AND (J.TIPO_CAMPANHA_DSC LIKE '%adq%' OR B.NOMBRE_DSC LIKE '%nuevo%')

AND C.NUM_RUC_CD NOT IN (

   SELECT NUM_DOCUMENTO FROM E_DW_VIEWS.V_FEEDBACK_TELEVENTAS

   WHERE 1 = 1

   AND (

       CATEGORIA IN ('CE', 'CNE', 'AC', 'NC') OR RESULTADO_LLAMADA LIKE '%(CE)%' OR RESULTADO_LLAMADA LIKE '%(AC)%'

         OR RESULTADO_LLAMADA LIKE '%NO ACEPTA CAMPANA%'

   )

   AND GESTION IN ('202306', '202305', '202304')

)

QUALIFY Row_Number() Over(PARTITION BY C.NUM_RUC_CD  ORDER BY B.PERIODO_VAL DESC) = 1

 

  -------------------------  LÓGICA CAIDAS POR FALTA DE CONTACTO (REPRESENTATES LEGALES - DNI) - 11K

  SELECT Z.*

    FROM(

      SELECT B.PERIODO_VAL,

             B.NOMBRE_DSC CAMPANHA,

           CASE WHEN REP.CODDOC IS NULL AND C.NUM_RUC_CD LIKE '10%' THEN SUBSTRING(C.NUM_RUC_CD,3,8) ELSE REP.CODDOC END DNI_RRLL,

           C.NUM_RUC_CD,

           B.BANCA_DSC,

           J.TIPO_CAMPANHA_DSC,

           A.MOTIVONOACTIVO_DSC

      FROM E_DW_VIEWS.V_VPC_NEG_EMPRESAS_CAMP_VIG A

      JOIN E_DW_VIEWS.V_VPC_NEG_CAMPANHAS_INST_VIG B ON B.CAMPANHA_INSTANCIA_ID=A.CAMPANHA_INSTANCIA_ID

      JOIN E_DW_VIEWS.V_VPC_NEG_EMPRESAS_VIG C ON C.EMPRESA_ID=A.EMPRESA_ID

      LEFT JOIN E_DW_VIEWS.V_VPC_NEG_CAMPANHAS_VIG J ON J.CAMPANHA_ID=B.CAMPANHA_ID

      LEFT JOIN E_DW_VIEWS.V_REP_LEGALES_SUNAT REP ON REP.NUMRUC = C.NUM_RUC_CD AND TIPDOC = '1' AND ESTADO = 0

      WHERE B.PERIODO_VAL IN ('202306', '202305', '202304')-- (SELECT MAX(PERIODO_VAL) FROM E_DW_VIEWS.V_VPC_NEG_CAMPANHAS_INST_VIG)

      AND A.MOTIVONOACTIVO_DSC LIKE '%CONTACTO%'

      AND C.NUM_RUC_CD <> '.'

      AND C.NUM_RUC_CD NOT LIKE ''

        AND (J.TIPO_CAMPANHA_DSC LIKE '%adq%' OR B.NOMBRE_DSC LIKE '%nuevo%')

        AND C.NUM_RUC_CD NOT IN (

               SELECT NUM_DOCUMENTO FROM E_DW_VIEWS.V_FEEDBACK_TELEVENTAS

               WHERE 1 = 1

               AND (

                   CATEGORIA IN ('CE', 'CNE', 'AC', 'NC') OR RESULTADO_LLAMADA LIKE '%(CE)%' OR RESULTADO_LLAMADA LIKE '%(AC)%'

                     OR RESULTADO_LLAMADA LIKE '%NO ACEPTA CAMPANA%'

               )

               AND GESTION IN ('202306', '202305', '202304')

            )

      QUALIFY Row_Number() Over(PARTITION BY CASE WHEN REP.CODDOC IS NULL AND C.NUM_RUC_CD LIKE '10%' THEN SUBSTRING(C.NUM_RUC_CD,3,8) ELSE REP.CODDOC END  ORDER BY J.TIPO_CAMPANHA_DSC ASC) = 1

    ) Z

    WHERE Z.DNI_RRLL IS NOT NULL

 

Revise this Paste

Your Name: Code Language: