dbo.abogados_salida_

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

CREATE OR ALTER PROCEDURE dbo.abogados_salida_  
AS
BEGIN
    SET NOCOUNT ON;
 declare @cuit varchar(20), 
   @monotributo varchar(50), 
   @iva varchar(50),
   @empleado varchar(max), 
   @fallecimiento date, 
   @validado varchar(50), 
   @error varchar(max) 


 DECLARE C_padron CURSOR FOR
  select cuit as CUIT,
  iif (isnull(monotributo,'') = '', replace(monotributo_autonomo,' - ACTIVO',''), monotributo) as Monotributo,
  iva as 'IVA',
  empleadores as 'Relación de dependecia', fecha_defuncion as 'Fallecimiento', 
  iif (procesos_cuit_enrichment_mas.nombre is null, 'NO VALIDADO','') as Validado
  from procesos_cuit_enrichment_mas 
  left join datos_personas on c01_cuit = cuit 
  where cliente = 3259411 and fecha_proceso = '2021-10-05'
  and cuit > '27270887991'
  order by cuit 

 OPEN C_Padron
 FETCH NEXT FROM C_Padron INTO @cuit,
         @monotributo ,
         @iva ,
         @empleado ,
         @fallecimiento ,
         @validado  
 WHILE @@fetch_status = 0
 BEGIN 
   set @error = ''
   if (@fallecimiento is null)
   begin
   select top 1 @error = texto_constancia  
    from padron_sin_constancia 
    where id_padron = (select id_padron from padrones where identificacion = @cuit and habilitado = 1) 
    order by created desc 
   end 

   insert into abogados_salida values (
      @cuit,
   @monotributo ,
   @iva ,
   @empleado ,
   @fallecimiento ,
   @validado, @error) 
  FETCH NEXT FROM C_Padron INTO @cuit,
          @monotributo ,
          @iva ,
          @empleado ,
          @fallecimiento ,
          @validado  

 END  
 CLOSE C_Padron
 DEALLOCATE C_Padron
END
GO

Used By

No items found