dbo.completa_clase

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
-- exec completa_clase
CREATE OR ALTER PROCEDURE dbo.completa_clase
AS
BEGIN
    SET NOCOUNT ON;
 declare @cuit varchar(20)
 declare @id int
 declare @clase int 
 declare @dni varchar(20)
 
 DECLARE bn CURSOR FOR
  select top 1000 c01_cuit, id_dato_persona 
    from DATOS_PERSONAS
    where visible = 1 
    and len(c01_cuit) = 11 
    and c02_fecha_nac is null and c02_anio_nac is null

 OPEN bn 
 Fetch next from bn INTO @cuit, @id 
  WHILE (@@FETCH_STATUS <> -1 )
  BEGIN
    --select @cuit, @id
    set @dni   = null 
    set @clase = null 

    set @dni = (select top 1 convert(int,cuerpo_clave) 
        from padrones 
                 where identificacion = @cuit
       and habilitado = 1) 
  
    if (@dni is not null) 
    begin
       set @clase = (select top 1 Column8
       from padron_electoral 
       where Column1 = @dni)
   end 
   
   if (@clase is not null and @clase != 0)
   begin
    update datos_personas set c02_anio_nac = @clase, modified = getdate()
     where id_dato_persona = @id 
      end 
      else
   begin 
       -- los que deja en '' es porque no los encontro, pero para que no los vuelva a procesar.
       update datos_personas set c02_anio_nac = '', modified = getdate()
     where id_dato_persona = @id 
   end 
    
      Fetch next from bn INTO @cuit, @id 
  END

 CLOSE bn
 DEALLOCATE bn 

END 

GO

Used By

No items found