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
/*
select * from domicilios_todos where cuit = '20225157937' and tipo_domicilio = 'E'
exec [actualizar_datos_con_padron] '20225157937'
select * from domicilios_todos where cuit = '20225157937' and tipo_domicilio = 'E'
select * from padron_electoral where documento = '22515793'
*/
CREATE OR ALTER PROCEDURE dbo.actualizar_sexo_con_padron
AS
BEGIN
SET NOCOUNT ON;
declare @documento varchar(20),
@apellidos varchar(200),
@nombre varchar(200),
@dni varchar(10),
@id_padron int
declare @tabla table
(sexo varchar(1),
id_electoral int)
DECLARE C_padron CURSOR FOR
/*select top 100 id_padron,
iif(apellidos is not null,apellidos,nombre_persona) as nombre,
cuerpo_clave
from padrones
where isnull(sexo,'')= ''
and habilitado = 1
and tipo_persona = 'F'
and len(identificacion) = 11
and identificador in (select identificador from identificadores where country_code = 'AR')
-- Solo lo hace para personas físicas.
and id_padron not in (select id_padron from padron_sin_sexo)
*/
select id_padron,
iif(apellidos is not null,apellidos,nombre_persona) as nombre,
cuerpo_clave
from padrones
where tipo_persona = 'F'
and habilitado = 1
and sexo = ''
-- Solo lo hace para personas físicas.
and ismodified > getdate()-30
OPEN C_Padron
FETCH NEXT FROM C_Padron INTO @id_padron, @nombre, @dni
WHILE @@fetch_status = 0
BEGIN
--
-- select 'Padrones', @id_padron, @nombre, @dni
--
insert into @tabla
select top 1 sexo,id_electoral
from padron_electoral
where documento = @dni
and @nombre like '%'+apellidos+'%'
and procesado is null
-- Si procesado = 1 ya paso por acá.
if((select isnull(sexo,'') from @tabla) != '')
begin
update padrones set sexo = (select sexo from @tabla),ismodified = getdate() where id_padron = @id_padron
update padron_electoral set procesado = 1 where documento = @dni and id_electoral = (select id_electoral from @tabla)
end
else
begin
insert into padron_sin_sexo (id_padron,created,documento_buscado) values (@id_padron,getdate(),@dni)
end
delete @tabla
FETCH NEXT FROM C_Padron INTO @id_padron, @nombre, @dni
END
CLOSE C_Padron
DEALLOCATE C_Padron
END
GO
GO
/*
select * from domicilios_todos where cuit = '20225157937' and tipo_domicilio = 'E'
exec [actualizar_datos_con_padron] '20225157937'
select * from domicilios_todos where cuit = '20225157937' and tipo_domicilio = 'E'
select * from padron_electoral where documento = '22515793'
*/
CREATE OR ALTER PROCEDURE dbo.actualizar_sexo_con_padron
AS
BEGIN
SET NOCOUNT ON;
declare @documento varchar(20),
@apellidos varchar(200),
@nombre varchar(200),
@dni varchar(10),
@id_padron int
declare @tabla table
(sexo varchar(1),
id_electoral int)
DECLARE C_padron CURSOR FOR
/*select top 100 id_padron,
iif(apellidos is not null,apellidos,nombre_persona) as nombre,
cuerpo_clave
from padrones
where isnull(sexo,'')= ''
and habilitado = 1
and tipo_persona = 'F'
and len(identificacion) = 11
and identificador in (select identificador from identificadores where country_code = 'AR')
-- Solo lo hace para personas físicas.
and id_padron not in (select id_padron from padron_sin_sexo)
*/
select id_padron,
iif(apellidos is not null,apellidos,nombre_persona) as nombre,
cuerpo_clave
from padrones
where tipo_persona = 'F'
and habilitado = 1
and sexo = ''
-- Solo lo hace para personas físicas.
and ismodified > getdate()-30
OPEN C_Padron
FETCH NEXT FROM C_Padron INTO @id_padron, @nombre, @dni
WHILE @@fetch_status = 0
BEGIN
--
-- select 'Padrones', @id_padron, @nombre, @dni
--
insert into @tabla
select top 1 sexo,id_electoral
from padron_electoral
where documento = @dni
and @nombre like '%'+apellidos+'%'
and procesado is null
-- Si procesado = 1 ya paso por acá.
if((select isnull(sexo,'') from @tabla) != '')
begin
update padrones set sexo = (select sexo from @tabla),ismodified = getdate() where id_padron = @id_padron
update padron_electoral set procesado = 1 where documento = @dni and id_electoral = (select id_electoral from @tabla)
end
else
begin
insert into padron_sin_sexo (id_padron,created,documento_buscado) values (@id_padron,getdate(),@dni)
end
delete @tabla
FETCH NEXT FROM C_Padron INTO @id_padron, @nombre, @dni
END
CLOSE C_Padron
DEALLOCATE C_Padron
END
GO
Depends On
2Used By
No items found