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 completar_cuit where cuit is null and procesado = 1
select * from completar_cuit where cuit is not null and procesado = 1
select * from completar_cuit where id = 95492
update completar_cuit set cuit = '23128947329', nombre_padron = 'HILALE MARIO EDUARDO' where id = 95492
select * from padrones where cuerpo_clave = '12894732'
select * from completar_cuit where nrodoc = '12894732'
--update completar_cuit
--set completar_cuit.cuit = identificacion, completar_cuit.nombre_padron=nombre_persona, procesado = 2
-- from completar_cuit
select * from completar_cuit
inner join padrones on (cuerpo_clave = format(nrodoc,'00000000') and habilitado = 1)
where procesado = 1 and cuit is null
and ismodified is not null and identificador in ('CUIL','CUIT')
select * from padrones where identificacion = '20164027954'
'
('06434037','24097762','93874159', '25251940','16674932')
*/
CREATE OR ALTER PROCEDURE dbo.completar_cuit_2_
AS
BEGIN
SET NOCOUNT ON;
declare @dni bigint
declare @nombre varchar(500)
declare @id int
declare @p_cuit varchar(20)
declare @p_nombre_padron varchar(500)
declare @dni1 varchar(20)
declare @dni2 varchar(20)
declare @resultado table (id int, cantidad int,nrodoc varchar(10), nombre varchar(500),
identificador varchar(10), cuit varchar(20),sexo char(1), nombre_padron varchar(200),ismodified datetime, marca bit)
DECLARE C_padron CURSOR FOR
select id,
nombre,
nrodoc
from completar_cuit
where (procesado = 1 and cuit is null) --and id > 167915
--or procesado = 2
order by id
OPEN C_Padron
FETCH NEXT FROM C_Padron INTO @id, @nombre, @dni
WHILE @@fetch_status = 0
BEGIN
set @dni1 = convert(varchar,@dni)
set @dni2 = format(@dni,'00000000')
set @p_cuit = null
set @p_nombre_padron = null
declare @cant int = 0
select @cant = count(*)
from padrones
where habilitado = 1 and (cuerpo_clave = @dni1 or cuerpo_clave = @dni2)
if (@cant = 0)
begin
insert into @resultado select @id, @cant, @dni, @nombre, null, null,null, null, null, null
--update completar_cuit set procesado = 9 where id = @id /* No se encuentra el dni en el padron */
end
else
begin
select @cant = count(*)
from padrones
where habilitado = 1 and (cuerpo_clave = @dni1 or cuerpo_clave = @dni2)
--and ismodified is not null and ismodified > '2022-12-16' -- Se lo ponemos despues de pasar por afip los que daban mas de 1
and identificador in ('CUIL','CUIT')
--and ((sexo='F' and identificacion like '27%') or (sexo='M' and identificacion like '20%'))
insert into @resultado
select @id, @cant, @dni, @nombre,
identificador, identificacion, sexo, nombre_persona,ismodified,
iif ((sexo='F' and identificacion like '27%') or (sexo='M' and identificacion like '20%'),'1','0')
from padrones
where habilitado = 1 and (cuerpo_clave = @dni1 or cuerpo_clave = @dni2)
--and ismodified is not null and ismodified > '2022-12-16' -- Se lo ponemos despues de pasar por afip los que daban mas de 1
and identificador in ('CUIL','CUIT')
--and ((sexo='F' and identificacion like '27%') or (sexo='M' and identificacion like '20%'))
end
if (@cant = 1)
begin
select @p_cuit = identificacion, @p_nombre_padron = nombre_persona
from padrones
where habilitado = 1 and (cuerpo_clave = @dni1 or cuerpo_clave = @dni2)
and ismodified is not null and ismodified > '2022-12-16' -- Se lo ponemos despues de pasar por afip los que daban mas de 1
and identificador in ('CUIL','CUIT')
/*
if (@p_cuit is not null and LEN(@p_cuit) = 11)
begin
update completar_cuit set cuit = @p_cuit, nombre_padron = @p_nombre_padron, procesado = 2 where id = @id
end */
end
FETCH NEXT FROM C_Padron INTO @id, @nombre, @dni
END
CLOSE C_Padron
DEALLOCATE C_Padron
select cantidad, count(distinct id) as total from @resultado group by cantidad order by cantidad
/*
-- Ponemos como procesado = 9 cuando no hay nada en padron para el dni
update completar_cuit set procesado = 9 where id in (
select id from @resultado where cantidad = 0)
*/
/*
select a.*,b.identificador, b.cuit, b.sexo,b.marca from @resultado a
inner join @resultado b on (a.id = b.id and b.cuit > a.cuit and b.nombre_padron = a.nombre_padron)
where a.cantidad = 3 and a.nombre_padron = a.nombre
order by a.id
*/
select nrodoc, nombre, cuit, '3', id, nombre_padron, ismodified from @resultado where cantidad > 1
/*
--Cuando queremos poner en consultar_afip los que encontro mas de 1
insert into consultar_afip (proceso, fecha, prioridad, procesado,cuit)
select 'completar_cuit','2022-12-16',1,0,cuit from @resultado where cantidad > 1
--select max(id) as ultimo_id from @resultado
*/
END
/*
select procesado, count(*) from completar_cuit
group by procesado
select * from completar_cuit where procesado = 1 and cuit is null
select * from padrones where cuerpo_clave in (select nrodoc from completar_cuit where procesado = 9)
)
select * from PANEL_CONTROL_JSON where cliente = 6059604
*/
update completar_cuit set procesado =1, cuit = null,nombre_padron = null
where procesado = 2
select * from completar_cuit where procesado = 2
GO
GO
/*
select * from completar_cuit where cuit is null and procesado = 1
select * from completar_cuit where cuit is not null and procesado = 1
select * from completar_cuit where id = 95492
update completar_cuit set cuit = '23128947329', nombre_padron = 'HILALE MARIO EDUARDO' where id = 95492
select * from padrones where cuerpo_clave = '12894732'
select * from completar_cuit where nrodoc = '12894732'
--update completar_cuit
--set completar_cuit.cuit = identificacion, completar_cuit.nombre_padron=nombre_persona, procesado = 2
-- from completar_cuit
select * from completar_cuit
inner join padrones on (cuerpo_clave = format(nrodoc,'00000000') and habilitado = 1)
where procesado = 1 and cuit is null
and ismodified is not null and identificador in ('CUIL','CUIT')
select * from padrones where identificacion = '20164027954'
'
('06434037','24097762','93874159', '25251940','16674932')
*/
CREATE OR ALTER PROCEDURE dbo.completar_cuit_2_
AS
BEGIN
SET NOCOUNT ON;
declare @dni bigint
declare @nombre varchar(500)
declare @id int
declare @p_cuit varchar(20)
declare @p_nombre_padron varchar(500)
declare @dni1 varchar(20)
declare @dni2 varchar(20)
declare @resultado table (id int, cantidad int,nrodoc varchar(10), nombre varchar(500),
identificador varchar(10), cuit varchar(20),sexo char(1), nombre_padron varchar(200),ismodified datetime, marca bit)
DECLARE C_padron CURSOR FOR
select id,
nombre,
nrodoc
from completar_cuit
where (procesado = 1 and cuit is null) --and id > 167915
--or procesado = 2
order by id
OPEN C_Padron
FETCH NEXT FROM C_Padron INTO @id, @nombre, @dni
WHILE @@fetch_status = 0
BEGIN
set @dni1 = convert(varchar,@dni)
set @dni2 = format(@dni,'00000000')
set @p_cuit = null
set @p_nombre_padron = null
declare @cant int = 0
select @cant = count(*)
from padrones
where habilitado = 1 and (cuerpo_clave = @dni1 or cuerpo_clave = @dni2)
if (@cant = 0)
begin
insert into @resultado select @id, @cant, @dni, @nombre, null, null,null, null, null, null
--update completar_cuit set procesado = 9 where id = @id /* No se encuentra el dni en el padron */
end
else
begin
select @cant = count(*)
from padrones
where habilitado = 1 and (cuerpo_clave = @dni1 or cuerpo_clave = @dni2)
--and ismodified is not null and ismodified > '2022-12-16' -- Se lo ponemos despues de pasar por afip los que daban mas de 1
and identificador in ('CUIL','CUIT')
--and ((sexo='F' and identificacion like '27%') or (sexo='M' and identificacion like '20%'))
insert into @resultado
select @id, @cant, @dni, @nombre,
identificador, identificacion, sexo, nombre_persona,ismodified,
iif ((sexo='F' and identificacion like '27%') or (sexo='M' and identificacion like '20%'),'1','0')
from padrones
where habilitado = 1 and (cuerpo_clave = @dni1 or cuerpo_clave = @dni2)
--and ismodified is not null and ismodified > '2022-12-16' -- Se lo ponemos despues de pasar por afip los que daban mas de 1
and identificador in ('CUIL','CUIT')
--and ((sexo='F' and identificacion like '27%') or (sexo='M' and identificacion like '20%'))
end
if (@cant = 1)
begin
select @p_cuit = identificacion, @p_nombre_padron = nombre_persona
from padrones
where habilitado = 1 and (cuerpo_clave = @dni1 or cuerpo_clave = @dni2)
and ismodified is not null and ismodified > '2022-12-16' -- Se lo ponemos despues de pasar por afip los que daban mas de 1
and identificador in ('CUIL','CUIT')
/*
if (@p_cuit is not null and LEN(@p_cuit) = 11)
begin
update completar_cuit set cuit = @p_cuit, nombre_padron = @p_nombre_padron, procesado = 2 where id = @id
end */
end
FETCH NEXT FROM C_Padron INTO @id, @nombre, @dni
END
CLOSE C_Padron
DEALLOCATE C_Padron
select cantidad, count(distinct id) as total from @resultado group by cantidad order by cantidad
/*
-- Ponemos como procesado = 9 cuando no hay nada en padron para el dni
update completar_cuit set procesado = 9 where id in (
select id from @resultado where cantidad = 0)
*/
/*
select a.*,b.identificador, b.cuit, b.sexo,b.marca from @resultado a
inner join @resultado b on (a.id = b.id and b.cuit > a.cuit and b.nombre_padron = a.nombre_padron)
where a.cantidad = 3 and a.nombre_padron = a.nombre
order by a.id
*/
select nrodoc, nombre, cuit, '3', id, nombre_padron, ismodified from @resultado where cantidad > 1
/*
--Cuando queremos poner en consultar_afip los que encontro mas de 1
insert into consultar_afip (proceso, fecha, prioridad, procesado,cuit)
select 'completar_cuit','2022-12-16',1,0,cuit from @resultado where cantidad > 1
--select max(id) as ultimo_id from @resultado
*/
END
/*
select procesado, count(*) from completar_cuit
group by procesado
select * from completar_cuit where procesado = 1 and cuit is null
select * from padrones where cuerpo_clave in (select nrodoc from completar_cuit where procesado = 9)
)
select * from PANEL_CONTROL_JSON where cliente = 6059604
*/
update completar_cuit set procesado =1, cuit = null,nombre_padron = null
where procesado = 2
select * from completar_cuit where procesado = 2
GO
Depends On
2Used By
No items found