dbo.procesar_renaper_1

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

2
Name Data Type Length Description
@accion varchar 50
@nombre_fuente varchar 50

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

CREATE OR ALTER PROCEDURE dbo.procesar_renaper_1
@accion varchar(50),
@nombre_fuente varchar(50)
--exec procesar_renaper_1 'dni_to_cuit','MAPFRE_21_08_2019'
--exec procesar_renaper_1 'actualizar_nacionalidad_existentes','MAPFRE_21_08_2019'

AS
BEGIN
 SET NOCOUNT ON;
 if(@accion = 'dni_to_cuit')
 begin
  DECLARE @dni varchar(20),@id_renaper int

  DECLARE db_cursor CURSOR FOR
  SELECT  dni,id_renaper
  FROM dbo.temp_renaper_proceso_1 where ( procesado is null or procesado = 0 ) and nacionalidad is null and identificacion is null
  and nombre_fuente = @nombre_fuente

  OPEN db_cursor
  FETCH NEXT FROM db_cursor INTO @dni,@id_renaper 

  WHILE @@FETCH_STATUS = 0
  BEGIN
  declare @identificacion varchar(20)
  set @identificacion = ''
  set @identificacion = (select top 1 identificacion from padrones where habilitado = 1 and cuerpo_clave = @dni)
  
  if(@identificacion != '')
  begin
   update temp_renaper_proceso_1 set identificacion = @identificacion where id_renaper = @id_renaper
  end
  
    FETCH NEXT FROM db_cursor INTO @dni,@id_renaper 
  END

  CLOSE db_cursor
  DEALLOCATE db_cursor
 end
 if(@accion = 'actualizar_nacionalidad_existentes')
 begin
  UPDATE t1
  SET t1.nacionalidad = t2.nacionalidad,
  t1.sexo = t2.sexo
  FROM RENAPER_INFO t2
  INNER JOIN temp_renaper_proceso_1 t1 ON t1.identificacion = t2.identificacion
  WHERE t2.identificacion is not null and t1.nombre_fuente = @nombre_fuente
  and nroError = 0
 end
END
GO

Used By

No items found