dbo.Habeas_Data_Solicitud_chequeo_previo

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

1
Name Data Type Length Description
@CUIT varchar 20

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
[Habeas_Data_Solicitud_chequeo_previo] '20330334968'
[Habeas_Data_Solicitud_chequeo_previo] '33033496'

[Habeas_Data_Solicitud_chequeo_previo] '27362065807'
[Habeas_Data_Solicitud_chequeo_previo] '20132970883'


select * from informes where id_tipo_informe = 671260 and estado_informe = 'E' order by fecha_ingreso desc
*/


CREATE OR ALTER PROCEDURE  dbo.Habeas_Data_Solicitud_chequeo_previo
@CUIT varchar(20)

AS

BEGIN
 SET NOCOUNT ON;
 set @CUIT = ltrim(rtrim(@CUIT))

 /* 29/08/2024: Agregado para que busque por dni, en caso que lo ingresado no es el CUIT */ 
 declare @dni varchar(8) = null 
 if (len(@cuit) <= 8)
  set @dni = right('00000000'+@Cuit,8)
 /**/
 
 declare @IDTipoInforme int = 671260
 declare @ingreso       date
 declare @entregado     date
 declare @estado        varchar(1)

 SELECT top 1 @ingreso = convert(date,fecha_ingreso), @entregado = convert(date,fecha_entregado), @estado = estado_informe 
   FROM INFORMES 
  WHERE id_tipo_informe = @IDTipoInforme
    /*  29/08/2024: si es un dni, que busque los informes que el numero contiene al dni 
        y descarta solo informes anulados, buscando todos los demas estados posibles, no solo E y K */

    --and numero = ltrim(rtrim(@CUIT))
    and (iif(@dni is null and numero = ltrim(rtrim(@CUIT)),1,iif(numero like '__'+@dni+'_',1,0))) = 1
    --and estado_informe in ('E','K')
    and estado_informe not in ('N') --> que no esté anulado
    order by fecha_ingreso 

 if (@ingreso > dateadd(month,-6,getdate()))
 begin
  if (@entregado is not null) select '1' as error, 'FIN' as motivo, CONVERT(varchar(10),@ingreso,103) as fecha
  
  if (@entregado is null)     select '1' as error, 'PROCESO' as motivo, CONVERT(varchar(10),@ingreso,103) as fecha 
 end 
 else 
 begin
 select '0' as error, 'ok' as motivo, null as fecha 
 end 
END

GO

Depends On

1

Used By

No items found