dbo.copyle_busqueda_dni

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.copyle_busqueda_dni

AS


BEGIN
    SET NOCOUNT ON;
declare @fecha_proceso date = convert(date,getdate())
declare @dni_procesar varchar(20)
DECLARE ProdInfo CURSOR FOR

select dni from temp_dni_copyle
OPEN ProdInfo

FETCH NEXT FROM ProdInfo INTO @dni_procesar

WHILE @@fetch_status = 0

 BEGIN
 
  declare @count_identificacion int
  declare @identificacion varchar(20)
  declare @cuit varchar(20)
  declare @relacion_dependencia int
  declare @nombre_persona varchar(200)
  set @count_identificacion = (select count(identificacion) from padrones where cuerpo_clave = @dni_procesar and habilitado = 1)
  
  if(@count_identificacion = 1)
   begin
    set @identificacion = (select identificacion from padrones where cuerpo_clave = @dni_procesar and habilitado = 1)
    set @nombre_persona = (select nombre_persona from padrones where cuerpo_clave = @dni_procesar and habilitado = 1)
   
    set @relacion_dependencia = (select COUNT(*) from empleados where cuil = @identificacion  and periodo >= (
    select  convert(varchar,Right(Year(getDate()-120),2)) + convert(varchar,Right(month(getDate()-120),2)) ) )
    if(@relacion_dependencia > 0)
     begin  
      insert into temp_copyle_output values(@identificacion,@dni_procesar,@nombre_persona,'Relación de dependencia')
     end
    else
     begin
      insert into temp_copyle_output values('',@dni_procesar,'','No tiene relación de dependencia')
     end  
   end
  else if(@count_identificacion = 0)
  begin
   insert into temp_copyle_output values('',@dni_procesar,'','El DNI no existe')
  end
  else
   begin

   DECLARE cursorRepetidos CURSOR FOR
    select identificacion from padrones where cuerpo_clave = @dni_procesar and habilitado = 1
    
    OPEN cursorRepetidos
    FETCH NEXT FROM cursorRepetidos INTO @cuit
    
    WHILE @@fetch_status = 0
     BEGIN
      set @nombre_persona = (select nombre_persona from padrones where identificacion = @cuit and habilitado = 1)
   
      set @relacion_dependencia = (select COUNT(*) from empleados where cuil = @cuit  and periodo >= (
      select  convert(varchar,Right(Year(getDate()-120),2)) + convert(varchar,Right(month(getDate()-120),2)) ) )
      if(@relacion_dependencia > 0)
       begin  
        insert into temp_copyle_output values(@cuit,@dni_procesar,@nombre_persona,'Relación de dependencia - DNI Duplicado')
       end
      else
       begin
        insert into temp_copyle_output values('',@dni_procesar,'','No tiene relación de dependencia - DNI Duplicado')
       end
      FETCH NEXT FROM cursorRepetidos INTO @cuit
     END
    CLOSE cursorRepetidos
    DEALLOCATE cursorRepetidos
   end
  FETCH NEXT FROM ProdInfo INTO @dni_procesar
 END

CLOSE ProdInfo

DEALLOCATE ProdInfo
END

GO

Used By

No items found