SELECT COALESCE(A.periodo, '202405') periodo, A.campania,
T.KEY_VALUE coddoc, M.KEY_VALUE num_ruc,
A.scorefinal_nr, A.primariesgo, A.oferta_calculada, A.rmaactual_bpe_final, A.rmaactual_consumo,
A.cemoferta, A.CEMOPERATIVO, A.costo_fondo_real, A.costo_fondo_redondeado, A.gasto_operativo,
A.margen_comercial, A.tasapiso_real, A.tasapiso_redondeado
FROM DLAB_MODELOS.TMP_VMVP_CAMPANIA_BPE_FROM_RIESGOS_X A ----------- todo la base de riesgos
LEFT JOIN E_DW_VIEWS.V_MST_ENCRIP_NRO_DOC_MDL_HISTDIA M
ON A.NUM_RUC = M.NRO_DOC
LEFT JOIN E_DW_VIEWS.V_MST_ENCRIP_NRO_DOC_MDL_HISTDIA T
ON A.CODDOC = T.NRO_DOC AND A.CODDOC <> '.' AND A.CODDOC IS NOT NULL AND A.CODDOC NOT LIKE ''
WHERE 1 = 1
AND A.NUM_RUC <> '.'
AND A.NUM_RUC IS NOT NULL
AND A.NUM_RUC NOT LIKE ''
Add a code snippet to your website: www.paste.org