SELECT A.PERIODO PERIODO_CAMPANIA,
       A.CAMPANHA,
	   A.SUBCAMPANHA,
	   A.CANAL,
	   A.INICIO,
	   A.FIN,
	   A.BANCA,
	   A.TIPO_CAMPANHA,
	   T.key_value NUM_DOC,
	   M.key_value NUM_RUC,
	   CAST(A.TASA AS FLOAT) TASA,
	   A.FLG_ACTIVO,
	   A.GESTION_TIPO,
	   A.GESTION_SUBTIPO,
	   A.ID_EMPRESA,
	   A.ID_CAMPANHA_INSTANCIA
FROM DLAB_PROGRAMADATOSVPC.TMP_VMVP_CAMPHANAS_TOTAL_2 A
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.NUM_DOC = T.NRO_DOC AND A.NUM_DOC <> &#039;.&#039; AND A.NUM_DOC IS NOT NULL AND A.NUM_DOC NOT LIKE &#039;&#039;
WHERE 1 = 1
AND A.NUM_RUC <> &#039;.&#039; 
AND A.NUM_RUC IS NOT NULL 
AND A.NUM_RUC NOT LIKE &#039;&#039;
--AND A.PERIODO <= (SELECT MAX(PERIODO) FROM DLAB_PROGRAMADATOSVPC.TMP_VMVP_CAMPHANAS_TOTAL_2)

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