--6.- PROVEEDORES 7.- CLIENTES
		    SELECT CASE WHEN LENGTH(RUC_PROV) = 11 AND RUC_PROV LIKE '10%' THEN SUBSTRING(RUC_PROV, 3, 8) 
		               ELSE RUC_PROV END NUMDOC
				  ,CASE WHEN LENGTH(RUC_PROV) = 11 AND RUC_PROV LIKE '10%' then '1' 
				        WHEN LENGTH(RUC_PROV) = 11 AND RUC_PROV LIKE '20%' then '2' 
				        WHEN LENGTH(RUC_PROV) = 8 then '1' 
				        ELSE '3' end  Cod_Tipo_Documento
		          ,MAX(cast(case WHEN LOWER(RELACION_DSC) LIKE '%cliente%' then '7.- CLIENTES'
				                 ELSE '6.- PROVEEDORES' end AS varchar(50))) CATEGORIA
			, 0 FLG_ADI
			, '.' logica_banca_mes_val, '.' logica_banca_fin_val
			, '.' Banca_Mes_Val, '.' Banca_Fin_Val
			, '.' LOGICA
			, 0 FLG_MERCADO_BPE
			, 0 FLG_NUEVO_MERCADO_BPE
			, 0 FLG_RESCATE_BPE
			, 0 FLG_RESCATE_MICRO
			, 0 FLG_PJ
		    , 0 FLG_CTA_NEG
		    , MAX(case when LOWER(RELACION_DSC) LIKE '%proveedor%' then 1 else 0 end) FLG_PROVEEDORES
			, MAX(case when LOWER(RELACION_DSC) LIKE '%cliente%' then 1 else 0 end) FLG_CLIENTES
			, 0 FLG_RESCATE_BE
		    , 0 FLG_BARRIDO_TLV_BPE
			, 0 FLG_PNCN
			, 0 FLG_RETAIL
			, 0 FLG_ADQUISION_RIESGOS
			, 0 FLG_RRLL_BPE_PJ
			, 0 FLG_RRLL_DNI_CARNETEXT
			FROM E_DW_VIEWS.V_MST_VPC_BASES_ECOSIS_BC
			WHERE CAST(TO_CHAR(FECHA_BASE_DT, &#039;YYYYMM&#039;) AS INT) <= 202406  --- este se reemplaza por el parametro del SP
			GROUP BY CASE WHEN LENGTH(RUC_PROV) = 11 AND RUC_PROV LIKE &#039;10%&#039; THEN SUBSTRING(RUC_PROV, 3, 8) 
		                  ELSE RUC_PROV END
		            ,CASE WHEN LENGTH(RUC_PROV) = 11 AND RUC_PROV LIKE &#039;10%&#039; then &#039;1&#039; 
				          WHEN LENGTH(RUC_PROV) = 11 AND RUC_PROV LIKE &#039;20%&#039; then &#039;2&#039; 
				          WHEN LENGTH(RUC_PROV) = 8 then &#039;1&#039; 
				          ELSE &#039;3&#039; END

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