dbo.LN_Fidecheck_ws_control

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

2
Name Data Type Length Description
@cuit varchar 20
@dias int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
select * from LN_Fidecheck_ws
select * from LN_demo_Fidecheck

*/

-- [LN_Fidecheck_ws_control] '20345734962',45

--select * from LN_Fidecheck_ws where cuit = '20345734962'
CREATE OR ALTER PROCEDURE dbo.LN_Fidecheck_ws_control
@cuit varchar(20),
@dias int = 30

AS

--LN_FIDECHECK_WS_SELECT 


BEGIN
    SET NOCOUNT ON;
 set @dias = @dias * (-1)
 
 declare @cantidad int = null
 /*
  set @cantidad = (select top 1 ISNULL(hallazgos,1) from LN_Fidecheck_ws 
  where (cuit = @cuit or DocumentoBuscado=@cuit)
  and created > dateadd(day,@dias,GETDATE())
  order by id_resultado desc)
 
  if (@cantidad is not null) 
  select top (@cantidad) id_resultado as id_resultado 
  from LN_Fidecheck_ws 
  where cuit = @cuit 
  and created > dateadd(day,@dias,GETDATE())
  order by id_resultado desc
 
  */


 declare @ultima_fecha date = (select max (convert(date,created)) from LN_Fidecheck_ws 
          where (cuit = @cuit /*or DocumentoBuscado=@cuit*/) 
          and created > dateadd(day,@dias,GETDATE()))

 set @cantidad = (select count(distinct id) from LN_Fidecheck_ws 
 where (cuit = @cuit/*or DocumentoBuscado=@cuit*/)
 and convert(date,created) =  @ultima_fecha)

 select top (@cantidad) a.id_resultado as id_resultado,


   case  
   when b.TipoFuente like 'Terrorista%' or b.TipoFuente = 'TER' then 1 -- Positive
   when b.TipoFuente like 'Sancionado%' or b.TipoFuente = 'SAN' then 2 -- Positive
   when b.TipoFuente in ('Sujeto Obligado','Sujetos Obligados','SO') then 9 -- Sujeto Obligado
   when isnull(a.relacion,'') != '' then 4 -- Relacionado
   when b.TipoFuente like 'Noticia%' then 10 -- (para que las noticias las deje ultimas) 
   else 3 -- PEP
   end as orden



  from LN_Fidecheck_ws b
  inner join LN_Fidecheck_ws_mas_datos a on b.id_resultado = a.id_resultado

  where (b.cuit = @cuit /*or b.DocumentoBuscado=@cuit*/)
    and convert(date,b.created) =  @ultima_fecha
  order by orden asc

END 

GO

Used By

No items found