DROP TABLE IF EXISTS d_mdl_vpc_disc.HM_GESTION_VPCONNECT_UP_SQAD
CREATE TABLE d_mdl_vpc_disc.HM_GESTION_VPCONNECT_UP_SQAD
WITH ( format = 'Parquet', 
         parquet_compression = 'SNAPPY', 
         partitioned_by = ARRAY['p_periodo'],
         external_location= 's3://sagemaker-us-east-1-058528764918/vpc/contactabilidad/athena_2/HM_GESTION_VPCONNECT_UP_SQAD/'
       )
AS (
    SELECT periodo_val periodo_campania,
        empresa_id,
        campanha_id,
        campanha_instancia_id,
        campanha campania,
        canal_dsc canal,
        cast(CASE WHEN inicio_dt LIKE '' THEN NULL else inicio_dt end as date) inicio_campania_dt,
        cast(CASE WHEN fin_date LIKE '' THEN NULL else fin_date end as date) fin_campania_dt,
        banca_dsc banca,
        tipo_campanha_dsc tipo_campania,
        CASE WHEN campanha='Nuevo Aprobado Agil' AND PERIODO_VAL IN ('202202', '202203') THEN atributo07_val ELSE atributo07_val END tasa,
        tipo_doc_cd,
        numdoc_val num_doc,
        CASE WHEN numruc_val IS NOT NULL AND numruc_val NOT LIKE '' THEN numruc_val else numdoc_val END num_ruc,
        cod_unico_cd cod_unico,
        razon_social_dsc razon_social,
        gestion_tipo_id,
        gestion_subtipo_id,
        gestion_tipo,
        gestion_subtipo,
        gestion_comentario,
        CAST(CASE WHEN fecha_registro_dt LIKE '' THEN NULL 
                  WHEN LENGTH(fecha_registro_dt) > 10 THEN registro_dsc
                  WHEN LENGTH(fecha_registro_dt) < 10 THEN registro_dsc
              else fecha_registro_dt end as date) fecha_gestion_dt_2,
        flg_activo,
        motivonoactivo_dsc motivo_no_activo,
        campo_informativo1_dsc,
        campo_informativo2_dsc,
         CASE WHEN gestion_tipo IS NOT NULL AND gestion_tipo NOT LIKE &#039;&#039; THEN 1 ELSE 0 END FLG_GESTION_VPCONNECT,
         CASE WHEN gestion_tipo IS NOT NULL AND gestion_tipo NOT LIKE &#039;&#039; AND gestion_tipo NOT LIKE &#039;%Sin Contacto%&#039; THEN 1 ELSE 0 END FLG_CE_VPCONNECT,
         CASE WHEN gestion_tipo LIKE &#039;%Acepta%&#039; AND gestion_tipo NOT LIKE &#039;%No%&#039; AND gestion_tipo NOT LIKE &#039;%Visita%&#039; THEN 1 ELSE 0 END FLG_ACEPTA_VPCONNECT,
         CASE WHEN gestion_tipo LIKE &#039;%Acepta%&#039; AND gestion_tipo LIKE &#039;%No%&#039; THEN 1 ELSE 0 END FLG_NO_ACEPTA_VPCONNECT,
         CASE WHEN gestion_tipo LIKE &#039;%Lo Pensa%&#039; THEN 1 ELSE 0 END FLG_LO_PENSARA_VPCONNECT    ,
         CASE WHEN gestion_tipo = &#039;No Califica&#039; THEN 1 ELSE 0 END FLG_NO_CALIFICA_VPCONNECT,
         CASE WHEN gestion_tipo LIKE &#039;%Desisti%&#039; THEN 1 ELSE 0 END FLG_DEISTE_VPCONNECT,
         periodo_val p_periodo
         FROM e_perm_aws.t_vpc_neg_empresas_vig
    )

Add a code snippet to your website: www.paste.org