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.igj_socios_duplicados
AS
BEGIN
SET NOCOUNT ON;
declare @cuit varchar(20)
declare @cuit_socio varchar(20)
declare @car_codigo char(3)
declare @c04_ultimo char(1)
declare @id_socios int
declare @cant int
declare @total_procesados int = 0
/* 1) Elimino los que quedaron duplicados: */
DECLARE C_Duplicados CURSOR FOR
select c01_cuit, c01_cuit_soc, car_codigo, c04_ultimo, COUNT(*), MIN(id_socios)
from socios
where fuente = 'IGJ' and visible = 1
group by c01_cuit, c01_cuit_soc, car_codigo, c04_ultimo
having COUNT(*) > 1
OPEN C_Duplicados
FETCH NEXT FROM C_Duplicados INTO @cuit,
@cuit_socio,
@car_codigo,
@c04_ultimo,
@cant,
@id_socios
WHILE @@fetch_status = 0
BEGIN
set @total_procesados = @total_procesados + 1
update socios set visible = 0, modified = GETDATE(), modified_by = 15342812 where id_socios = @id_socios
FETCH NEXT FROM C_Duplicados INTO @cuit,
@cuit_socio,
@car_codigo,
@c04_ultimo,
@cant,
@id_socios
END
CLOSE C_Duplicados
DEALLOCATE C_Duplicados
select @total_procesados as procesados
/* 2) Los que estaban con el cargo correcto los dejo y paso a no visible los IGJ */
DECLARE C_cursor CURSOR FOR
select c01_cuit, c01_cuit_soc, car_codigo, c04_ultimo, id_socios
from socios
where fuente = 'IGJ' and car_codigo = 'IGJ' and visible = 1
and exists (select * from socios b
where b.c01_cuit = socios.c01_cuit and b.c01_cuit_soc = socios.c01_cuit_soc
and b.c04_ultimo = 'N' and b.car_codigo != 'IGJ' and b.visible = 1)
OPEN C_cursor
set @total_procesados = 0
declare @id_socios_2 int
FETCH NEXT FROM C_cursor INTO @cuit,
@cuit_socio,
@car_codigo,
@c04_ultimo,
@id_socios
WHILE @@fetch_status = 0
BEGIN
set @total_procesados = @total_procesados + 1
set @id_socios_2 = null
set @id_socios_2 = (select TOP 1 id_socios
from socios
where c01_cuit = @cuit and c01_cuit_soc = @cuit_socio
and c04_ultimo = 'N' and car_codigo != 'IGJ' and visible = 1
order by id_socios desc)
if (@id_socios_2 is not null)
begin
update socios set c04_ultimo = 'S', modified = GETDATE(), modified_by = 15342812 where id_socios = @id_socios_2
update socios set visible = 0, modified = GETDATE(), modified_by = 15342812 where id_socios = @id_socios
end
FETCH NEXT FROM C_cursor INTO @cuit,
@cuit_socio,
@car_codigo,
@c04_ultimo,
@id_socios
END
CLOSE C_cursor
DEALLOCATE C_cursor
select @total_procesados as procesados
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.igj_socios_duplicados
AS
BEGIN
SET NOCOUNT ON;
declare @cuit varchar(20)
declare @cuit_socio varchar(20)
declare @car_codigo char(3)
declare @c04_ultimo char(1)
declare @id_socios int
declare @cant int
declare @total_procesados int = 0
/* 1) Elimino los que quedaron duplicados: */
DECLARE C_Duplicados CURSOR FOR
select c01_cuit, c01_cuit_soc, car_codigo, c04_ultimo, COUNT(*), MIN(id_socios)
from socios
where fuente = 'IGJ' and visible = 1
group by c01_cuit, c01_cuit_soc, car_codigo, c04_ultimo
having COUNT(*) > 1
OPEN C_Duplicados
FETCH NEXT FROM C_Duplicados INTO @cuit,
@cuit_socio,
@car_codigo,
@c04_ultimo,
@cant,
@id_socios
WHILE @@fetch_status = 0
BEGIN
set @total_procesados = @total_procesados + 1
update socios set visible = 0, modified = GETDATE(), modified_by = 15342812 where id_socios = @id_socios
FETCH NEXT FROM C_Duplicados INTO @cuit,
@cuit_socio,
@car_codigo,
@c04_ultimo,
@cant,
@id_socios
END
CLOSE C_Duplicados
DEALLOCATE C_Duplicados
select @total_procesados as procesados
/* 2) Los que estaban con el cargo correcto los dejo y paso a no visible los IGJ */
DECLARE C_cursor CURSOR FOR
select c01_cuit, c01_cuit_soc, car_codigo, c04_ultimo, id_socios
from socios
where fuente = 'IGJ' and car_codigo = 'IGJ' and visible = 1
and exists (select * from socios b
where b.c01_cuit = socios.c01_cuit and b.c01_cuit_soc = socios.c01_cuit_soc
and b.c04_ultimo = 'N' and b.car_codigo != 'IGJ' and b.visible = 1)
OPEN C_cursor
set @total_procesados = 0
declare @id_socios_2 int
FETCH NEXT FROM C_cursor INTO @cuit,
@cuit_socio,
@car_codigo,
@c04_ultimo,
@id_socios
WHILE @@fetch_status = 0
BEGIN
set @total_procesados = @total_procesados + 1
set @id_socios_2 = null
set @id_socios_2 = (select TOP 1 id_socios
from socios
where c01_cuit = @cuit and c01_cuit_soc = @cuit_socio
and c04_ultimo = 'N' and car_codigo != 'IGJ' and visible = 1
order by id_socios desc)
if (@id_socios_2 is not null)
begin
update socios set c04_ultimo = 'S', modified = GETDATE(), modified_by = 15342812 where id_socios = @id_socios_2
update socios set visible = 0, modified = GETDATE(), modified_by = 15342812 where id_socios = @id_socios
end
FETCH NEXT FROM C_cursor INTO @cuit,
@cuit_socio,
@car_codigo,
@c04_ultimo,
@id_socios
END
CLOSE C_cursor
DEALLOCATE C_cursor
select @total_procesados as procesados
END
GO
Depends On
1Used By
No items found