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 ( 2 years ago )
 select
   t.PERIODO, t.CAMPANIA, 
   CASE WHEN t.COD_UNICO='NULL' THEN NULL ELSE t.COD_UNICO END COD_UNICO,       
   t.NUMERORUC NUM_RUC,  
   t.CODDOC,
   t.SCOREFINAL_BUCKET,
   t.SCOREFINAL_NR, t.PRIMARIESGO, 
   t.[OFERTACALCULADA ] OFERTA_CALCULADA,
   t.[RMAACTUAL_BPE_FINAL ] RMAACTUAL_BPE_FINAL,
   t.[RMAACTUAL_CONSUMO ] RMAACTUAL_CONSUMO,
   t.[CEMOFERTA ] CEMOFERTA,
   t.[CEMOPERATIVO ] CEMOPERATIVO, 
   cf.COSTO_FONDO_REAL, cf.COSTO_FONDO_REDONDEADO, 
   g.GASTO_OPERATIVO, g.MARGEN_COMERCIAL, 
   t.PRIMARIESGO + cf.COSTO_FONDO_REAL + g.GASTO_OPERATIVO + (CASE WHEN t.PERIODO < '202208' THEN g.MARGEN_COMERCIAL ELSE cc.Margen END) AS TASAPISO_REAL,       
   t.PRIMARIESGO + cf.COSTO_FONDO_REDONDEADO + g.GASTO_OPERATIVO + (CASE WHEN t.PERIODO < '202208' THEN g.MARGEN_COMERCIAL ELSE cc.Margen END)AS TASAPISO_REDONDEADO    
   --INTO TMP_HM_CAMPANIAS_BPE_1        --INTO ODS.HM_CAMPANIA_BPE    
   from STG.T_CARGA_CAMPANHA_NPRE_APRO t    
   LEFT JOIN [STG].[T_COSTO_FONDO_HISTORICA] cf 
   on cf.PERIODO = t.PERIODO    
   LEFT JOIN [STG].[T_GO_MG_H] g 
   on g.PERIODO = t.PERIODO 
   LEFT JOIN (
        SELECT *
		FROM (SELECT ROW_NUMBER() OVER(PARTITION BY  periodo, campaña, score ORDER BY clientes DESC) orden, *
		from [dbo].[GESCOM_FORMULA_TASAS_BPE_NUEVOS]) A
		WHERE ORDEN = 1
   ) CC
   ON t.periodo = cc.periodo
   AND (
       CASE WHEN t.campania like '%Eco%' Then 'ECOSISTEMAS'
            WHEN t.campania like '%Nuevos Pre%' Then 'NUEVOS PRE'
            WHEN t.campania like '%Nuevos Ap%' Then 'NUEVOS AP'
		ELSE 'X' END
      ) = (
	   CASE WHEN cc.campaña like '%Eco%' Then 'ECOSISTEMAS'
            WHEN cc.campaña  like '%NUEVOS PRE%' Then 'NUEVOS PRE'
            WHEN cc.campaña  like '%NUEVOS AP%' Then 'NUEVOS AP'
		ELSE 'X' END
	  )
	AND t.SCOREFINAL_BUCKET = CC.Score

 

Revise this Paste

Your Name: Code Language: