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.subcontratistas_amx2_
AS
BEGIN
SET NOCOUNT ON;
declare @cuit_contratista varchar(20),
@contraparte_contratista int,
@cuit_subcontratista varchar(20),
@contraparte_subcontratista int,
@tipo_servicio varchar(10),
@familia_subcontratista int,
@familia_en_base int,
@vigente_desde date,
@vigente_hasta date,
@fecha_carga date,
@fecha_modificado date,
@fecha_baja date,
@fecha_actualizado_sql date,
@id int
declare @i int = 0
declare @J int = 0
declare @k int = 0
declare @id_padron int = null
declare @contraparte_nueva int
declare @vigencia_desde date
declare @vigencia_hasta date
DECLARE C_Cursor CURSOR FOR
select cuit_contratista,
contraparte_contratista,
cuit_subcontratista,
contraparte_subcontratista,
tipo_servicio,
familia_subcontratista,
familia_en_base,
vigente_desde,
vigente_hasta,
fecha_carga,
fecha_modificado,
fecha_baja,
fecha_actualizado_sql, id
from subcontratistas_amx2
where accion = 'DISTINTA'
--and ((len(cuit_contratista) = 11 and len(cuit_subcontratista) = 11)
-- or cuit_contratista like 'CHE%')
--select * from subcontratistas_amx where contraparte_contratista is null
--select * from users where user_id = 94437923
OPEN C_Cursor
FETCH NEXT FROM C_Cursor INTO
@cuit_contratista,
@contraparte_contratista,
@cuit_subcontratista,
@contraparte_subcontratista,
@tipo_servicio,
@familia_subcontratista,
@familia_en_base,
@vigente_desde,
@vigente_hasta,
@fecha_carga,
@fecha_modificado,
@fecha_baja,
@fecha_actualizado_sql,
@id
WHILE @@fetch_status = 0
BEGIN
set @i = @i + 1
if (@contraparte_contratista is null)
begin
set @id_padron = null
set @id_padron = (select top 1 id_padron from padrones
where identificacion = @cuit_contratista and habilitado = 1)
if (@id_padron is not null and
(select count(*) from ln_contrapartes
where cliente = 5546348
and id_padron = @id_padron
and subcontratista = 0
and activo = 1) = 1)
begin
set @contraparte_contratista = (select contraparte from ln_contrapartes
where cliente = 5546348
and id_padron = @id_padron
and subcontratista = 0
and activo = 1)
update subcontratistas_amx2
set contraparte_contratista = @contraparte_contratista
where id = @id
end
end
if (@contraparte_contratista is not null and @contraparte_subcontratista is null)
begin
set @id_padron = null
set @id_padron = (select top 1 id_padron from padrones
where identificacion = @cuit_subcontratista and habilitado = 1)
if (@id_padron is not null and
(select count(*) from ln_contrapartes
where cliente = 5546348
and id_padron = @id_padron
and subcontratista = 1
and activo = 1
and id_padre = @contraparte_contratista) = 1)
begin
set @contraparte_subcontratista = (select contraparte from ln_contrapartes
where cliente = 5546348
and id_padron = @id_padron
and subcontratista = 1
and activo = 1
and id_padre = @contraparte_contratista)
update subcontratistas_amx2
set contraparte_subcontratista = @contraparte_subcontratista
where id = @id
end
end
if (@contraparte_contratista is not null and @contraparte_subcontratista is not null)
begin
if (select count(*) from ln_contrapartes
where cliente = 5546348
and contraparte = @contraparte_subcontratista
and id_padre = @contraparte_contratista
and subcontratista = 1
and activo = 1) = 1
begin
SET @j = @j + 1
set @vigencia_desde = '1901-01-01'
set @vigencia_hasta = '1901-01-01'
select @vigencia_desde = vigencia_desde, @vigencia_hasta = vigencia_hasta
from ln_contrapartes
where cliente = 5546348
and contraparte = @contraparte_subcontratista
and id_padre = @contraparte_contratista
and subcontratista = 1
and activo = 1
if (@fecha_baja is not null) set @vigente_hasta = @fecha_baja
update ln_contrapartes
set vigencia_desde = @vigente_desde,
vigencia_hasta = @vigente_hasta,
modified = convert(date,getdate()),
modified_by = 527975456 -- user marita
where cliente = 5546348
and contraparte = @contraparte_subcontratista
and id_padre = @contraparte_contratista
and subcontratista = 1
and activo = 1
/*
update subcontratistas_amx2
set accion = 'DISTINTA'
where id = @id */
end
end
if (@contraparte_contratista is not null and @contraparte_subcontratista is null)
begin
update subcontratistas_amx2
set accion = 'INSERT'
where id = @id
end
FETCH NEXT FROM C_Cursor INTO
@cuit_contratista,
@contraparte_contratista,
@cuit_subcontratista,
@contraparte_subcontratista,
@tipo_servicio,
@familia_subcontratista,
@familia_en_base,
@vigente_desde,
@vigente_hasta,
@fecha_carga,
@fecha_modificado,
@fecha_baja,
@fecha_actualizado_sql,
@id
END
CLOSE C_Cursor
DEALLOCATE C_Cursor
select @i as leidos, @j as actualizados, @k as altas
END
GO
GO
/*
*/
CREATE OR ALTER PROCEDURE dbo.subcontratistas_amx2_
AS
BEGIN
SET NOCOUNT ON;
declare @cuit_contratista varchar(20),
@contraparte_contratista int,
@cuit_subcontratista varchar(20),
@contraparte_subcontratista int,
@tipo_servicio varchar(10),
@familia_subcontratista int,
@familia_en_base int,
@vigente_desde date,
@vigente_hasta date,
@fecha_carga date,
@fecha_modificado date,
@fecha_baja date,
@fecha_actualizado_sql date,
@id int
declare @i int = 0
declare @J int = 0
declare @k int = 0
declare @id_padron int = null
declare @contraparte_nueva int
declare @vigencia_desde date
declare @vigencia_hasta date
DECLARE C_Cursor CURSOR FOR
select cuit_contratista,
contraparte_contratista,
cuit_subcontratista,
contraparte_subcontratista,
tipo_servicio,
familia_subcontratista,
familia_en_base,
vigente_desde,
vigente_hasta,
fecha_carga,
fecha_modificado,
fecha_baja,
fecha_actualizado_sql, id
from subcontratistas_amx2
where accion = 'DISTINTA'
--and ((len(cuit_contratista) = 11 and len(cuit_subcontratista) = 11)
-- or cuit_contratista like 'CHE%')
--select * from subcontratistas_amx where contraparte_contratista is null
--select * from users where user_id = 94437923
OPEN C_Cursor
FETCH NEXT FROM C_Cursor INTO
@cuit_contratista,
@contraparte_contratista,
@cuit_subcontratista,
@contraparte_subcontratista,
@tipo_servicio,
@familia_subcontratista,
@familia_en_base,
@vigente_desde,
@vigente_hasta,
@fecha_carga,
@fecha_modificado,
@fecha_baja,
@fecha_actualizado_sql,
@id
WHILE @@fetch_status = 0
BEGIN
set @i = @i + 1
if (@contraparte_contratista is null)
begin
set @id_padron = null
set @id_padron = (select top 1 id_padron from padrones
where identificacion = @cuit_contratista and habilitado = 1)
if (@id_padron is not null and
(select count(*) from ln_contrapartes
where cliente = 5546348
and id_padron = @id_padron
and subcontratista = 0
and activo = 1) = 1)
begin
set @contraparte_contratista = (select contraparte from ln_contrapartes
where cliente = 5546348
and id_padron = @id_padron
and subcontratista = 0
and activo = 1)
update subcontratistas_amx2
set contraparte_contratista = @contraparte_contratista
where id = @id
end
end
if (@contraparte_contratista is not null and @contraparte_subcontratista is null)
begin
set @id_padron = null
set @id_padron = (select top 1 id_padron from padrones
where identificacion = @cuit_subcontratista and habilitado = 1)
if (@id_padron is not null and
(select count(*) from ln_contrapartes
where cliente = 5546348
and id_padron = @id_padron
and subcontratista = 1
and activo = 1
and id_padre = @contraparte_contratista) = 1)
begin
set @contraparte_subcontratista = (select contraparte from ln_contrapartes
where cliente = 5546348
and id_padron = @id_padron
and subcontratista = 1
and activo = 1
and id_padre = @contraparte_contratista)
update subcontratistas_amx2
set contraparte_subcontratista = @contraparte_subcontratista
where id = @id
end
end
if (@contraparte_contratista is not null and @contraparte_subcontratista is not null)
begin
if (select count(*) from ln_contrapartes
where cliente = 5546348
and contraparte = @contraparte_subcontratista
and id_padre = @contraparte_contratista
and subcontratista = 1
and activo = 1) = 1
begin
SET @j = @j + 1
set @vigencia_desde = '1901-01-01'
set @vigencia_hasta = '1901-01-01'
select @vigencia_desde = vigencia_desde, @vigencia_hasta = vigencia_hasta
from ln_contrapartes
where cliente = 5546348
and contraparte = @contraparte_subcontratista
and id_padre = @contraparte_contratista
and subcontratista = 1
and activo = 1
if (@fecha_baja is not null) set @vigente_hasta = @fecha_baja
update ln_contrapartes
set vigencia_desde = @vigente_desde,
vigencia_hasta = @vigente_hasta,
modified = convert(date,getdate()),
modified_by = 527975456 -- user marita
where cliente = 5546348
and contraparte = @contraparte_subcontratista
and id_padre = @contraparte_contratista
and subcontratista = 1
and activo = 1
/*
update subcontratistas_amx2
set accion = 'DISTINTA'
where id = @id */
end
end
if (@contraparte_contratista is not null and @contraparte_subcontratista is null)
begin
update subcontratistas_amx2
set accion = 'INSERT'
where id = @id
end
FETCH NEXT FROM C_Cursor INTO
@cuit_contratista,
@contraparte_contratista,
@cuit_subcontratista,
@contraparte_subcontratista,
@tipo_servicio,
@familia_subcontratista,
@familia_en_base,
@vigente_desde,
@vigente_hasta,
@fecha_carga,
@fecha_modificado,
@fecha_baja,
@fecha_actualizado_sql,
@id
END
CLOSE C_Cursor
DEALLOCATE C_Cursor
select @i as leidos, @j as actualizados, @k as altas
END
GO
Depends On
3Used By
No items found