dbo.obtener_trazabilidad_coface

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

2
Name Data Type Length Description
@contraparte int 4
@gestion int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
-- =============================================
-- Author: <Marita Soria>
-- Create date: <03/02/2023>
-- Description: obtiene los registros de trazabilidad de Estados COFACE de la gestion 
-- =============================================

[obtener_trazabilidad_coface] 152883
[SAAS_historial] 0,0,195053

LN_excepciones_final_ 'search', 164729

select * from SAAS_Historial_Consultas where contraparte = 195053
select * from ln_score_detalle_killer where contraparte = 195053
select * from ln_contraparte_indicadores where contraparte = 195053
select * from ln_contraparte_indicadores where indicador  = 355 and valor_numerico = -100


exec LN_dashboard_cliente 'AprobacionFormales', 515494256, null, null, 195053

declare @score_calc varchar(max) 
 EXEC LN_score_formal_antiguedad_edad 195053, @score_calc OUTPUT
 select @score_calc




select * from ln_indicadores where producto = 2042
*/

CREATE OR ALTER PROCEDURE dbo.obtener_trazabilidad_coface
@contraparte int, 
@gestion int = null 

AS
BEGIN
 SET NOCOUNT ON;
 if (@gestion is null)
    select @gestion = gestion from ln_gestiones 
    where contraparte = @contraparte 
    and vigente = 1
    and desde <= GETDATE()
    and hasta >= GETDATE()

 select distinct t.contraparte, 
  convert(varchar(16),t.created,126) as dia_hora,

 convert(date, t.created) as fecha, 
 convert(varchar, t.created,103) as fecha_dmy, 
 upper(t.accion) as indicador, 
 convert(varchar(max),texto) as texto, 
 t.valor_texto_old, 
 convert(varchar(max),t.valor_memo_old) as valor_old, 
 t.valor_texto_new, 
 convert(varchar(max),t.valor_memo_new) as valor_new, 
 iif (detalle_killer_new is not null, convert(varchar(max),detalle_killer_new), convert(varchar(max),detalle_puntos_new)) as motivo ,
 null as usuario 
 from trazabilidad t
 inner join ln_gestiones g on (g.contraparte = t.contraparte)
 where t.id_plataforma = 'INDICADOR' 
 and t.accion in (select clave_indicador from LN_indicadores where producto = 2042)
 and t.contraparte = @contraparte
 and t.created between g.desde and g.hasta 
 and g.gestion = @gestion 

 union
 
 SELECT e.contraparte, 
  convert(varchar(16),e.created,126) as dia_hora,

   convert(date, e.created) as fecha, 
   convert(varchar, e.created,103) as fecha_dmy, 
   'EXCEPCION' as indicador, 
   'Excepción: Cambio de estado' as texto, 
   null as valor_texto_old, 
   null as valor_old, 
   e.tipo_excepcion as valor_texto_new, 
   iif(e.tipo_excepcion='V','APROBAR','RECHAZAR') as valor_new, 
   convert(varchar(max),e.texto_excepcion) as motivo, 
   iif(users2.user_id is not null,
   (isnull(users.first_name,'') + ' ' + isnull(users.last_name,'')),
   (isnull(users.first_name,'') + ' ' + isnull(users.last_name,''))) as usuario
   FROM LN_excepciones_final e
  inner join ln_gestiones g on (g.contraparte = e.contraparte)
  LEFT OUTER JOIN users on e.created_by = users.user_id
  LEFT OUTER JOIN users users2 on e.created_by = users2.user_id


   WHERE e.contraparte = @contraparte
     and e.created between g.desde and g.hasta 
     and g.gestion = @gestion 

 order by dia_hora --fecha




END 



/*
select * from ln_contrapartes where id_padron in 
(select id_padron from padrones where identificacion = '30717820904')
*/

GO

Used By

No items found