Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @fecha_desde | date | 3 | |
| @fecha_hasta | date | 3 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: María Inés Soria
-- Create date: 29/01/2018
-- Description: Busca los registros cargados en sociedades_consituciones,
-- y si tiene cuit de la empresa, del integrante y el cargo,
-- si ya esta en la tabla socios, marca como no visible el que esta y lo carga con el cargo que viene en sociedades_constituciones
-- si no esta en la tabla socios, lo carga
-- =============================================
--
--select c01_cuit as c, c01_cuit_soc as s, * from socios where created >= '2018-02-01' and created_by = 1 order by c,s
--select documento_soc as c, cuit_int as s, * from sociedades_constituciones where procesado_socios is not null order by c, s
CREATE OR ALTER PROCEDURE dbo.proceso_socios_sociedades_constituciones
@fecha_desde date = null,
@fecha_hasta date = null
AS
BEGIN
if (@fecha_desde is null) set @fecha_desde = CONVERT(date, getdate())
if (@fecha_hasta is null) set @fecha_hasta = CONVERT(date, getdate())
declare @id int,
@cant int,
@c01_cuit varchar(50),
@c01_cuit_soc varchar(50),
@car_codigo varchar(50),
@c04_periodo_desde varchar(50)
DECLARE bn CURSOR FOR
select
sociedades_constituciones.id_fide,
documento_soc as c01_cuit,
IIF(len(cuit_int)=11,cuit_int, cuit_integrante) as c01_cuit_soc,
cargos.car_codigo as car_codigo,
convert(char(7),fecha_publicacion) as c04_periodo_desde
from sociedades_constituciones
inner join cargos -- Solo va a pasar cargos existentes
on cargos.car_nombre = sociedades_constituciones.cargo
or cargos.car_nombre_2 = sociedades_constituciones.cargo
or cargos.car_nombre_3 = sociedades_constituciones.cargo
or cargos.car_nombre_4 = sociedades_constituciones.cargo
or cargos.car_nombre_5 = sociedades_constituciones.cargo
where documento_soc like '3__________'
and (cuit_int like '2__________' or cuit_integrante like '2__________')
and isnull(cargo,'') != ''
and procesado_socios is null
--and CONVERT(date, created) between @fecha_desde and @fecha_hasta
union
select
sociedades_constituciones.id_fide,
documento_soc as c01_cuit,
IIF(len(cuit_int)=11,cuit_int, cuit_integrante) as c01_cuit_soc,
cargos.car_codigo as car_codigo,
convert(char(7),fecha_publicacion) as c04_periodo_desde
from sociedades_constituciones
inner join cargos -- Solo va a pasar cargos existentes
on cargos.car_nombre = ltrim(rtrim(replace(replace(sociedades_constituciones.cargo,'CESIONARIO',''),' - ',' ')))
or cargos.car_nombre_2 = ltrim(rtrim(replace(replace(sociedades_constituciones.cargo,'CESIONARIO',''),' - ',' ')))
or cargos.car_nombre_3 = ltrim(rtrim(replace(replace(sociedades_constituciones.cargo,'CESIONARIO',''),' - ',' ')))
or cargos.car_nombre_4 = ltrim(rtrim(replace(replace(sociedades_constituciones.cargo,'CESIONARIO',''),' - ',' ')))
or cargos.car_nombre_5 = ltrim(rtrim(replace(replace(sociedades_constituciones.cargo,'CESIONARIO',''),' - ',' ')))
where documento_soc like '3__________'
and (cuit_int like '2__________' or cuit_integrante like '2__________')
and isnull(cargo,'') like 'CESIONARIO%'
and procesado_socios is null
order by sociedades_constituciones.id_fide desc
OPEN bn
Fetch next from bn INTO
@id,
@c01_cuit,
@c01_cuit_soc,
@car_codigo,
@c04_periodo_desde
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
set @cant = 0
set @cant = (select COUNT(*) from socios
where c01_cuit = @c01_cuit
and c01_cuit_soc = @c01_cuit_soc
and visible = 1)
if (@cant > 0)
begin
update socios
set visible = 0,
modified = GETDATE(),
modified_by = '1'
where c01_cuit = @c01_cuit
and c01_cuit_soc = @c01_cuit_soc
end
insert into socios
(
c01_cuit,
c01_cuit_soc,
car_codigo,
c04_ultimo,
visible,
c04_periodo_desde,
created,
created_by)
values
(
@c01_cuit,
@c01_cuit_soc,
@car_codigo,
'S',
'1',
@c04_periodo_desde,
GETDATE(),
'1')
update sociedades_constituciones
set procesado_socios = 'S'
where id_fide = @id
Fetch next from bn INTO
@id,
@c01_cuit,
@c01_cuit_soc,
@car_codigo,
@c04_periodo_desde
END
CLOSE bn
DEALLOCATE bn
END
GO
GO
-- =============================================
-- Author: María Inés Soria
-- Create date: 29/01/2018
-- Description: Busca los registros cargados en sociedades_consituciones,
-- y si tiene cuit de la empresa, del integrante y el cargo,
-- si ya esta en la tabla socios, marca como no visible el que esta y lo carga con el cargo que viene en sociedades_constituciones
-- si no esta en la tabla socios, lo carga
-- =============================================
--
--select c01_cuit as c, c01_cuit_soc as s, * from socios where created >= '2018-02-01' and created_by = 1 order by c,s
--select documento_soc as c, cuit_int as s, * from sociedades_constituciones where procesado_socios is not null order by c, s
CREATE OR ALTER PROCEDURE dbo.proceso_socios_sociedades_constituciones
@fecha_desde date = null,
@fecha_hasta date = null
AS
BEGIN
if (@fecha_desde is null) set @fecha_desde = CONVERT(date, getdate())
if (@fecha_hasta is null) set @fecha_hasta = CONVERT(date, getdate())
declare @id int,
@cant int,
@c01_cuit varchar(50),
@c01_cuit_soc varchar(50),
@car_codigo varchar(50),
@c04_periodo_desde varchar(50)
DECLARE bn CURSOR FOR
select
sociedades_constituciones.id_fide,
documento_soc as c01_cuit,
IIF(len(cuit_int)=11,cuit_int, cuit_integrante) as c01_cuit_soc,
cargos.car_codigo as car_codigo,
convert(char(7),fecha_publicacion) as c04_periodo_desde
from sociedades_constituciones
inner join cargos -- Solo va a pasar cargos existentes
on cargos.car_nombre = sociedades_constituciones.cargo
or cargos.car_nombre_2 = sociedades_constituciones.cargo
or cargos.car_nombre_3 = sociedades_constituciones.cargo
or cargos.car_nombre_4 = sociedades_constituciones.cargo
or cargos.car_nombre_5 = sociedades_constituciones.cargo
where documento_soc like '3__________'
and (cuit_int like '2__________' or cuit_integrante like '2__________')
and isnull(cargo,'') != ''
and procesado_socios is null
--and CONVERT(date, created) between @fecha_desde and @fecha_hasta
union
select
sociedades_constituciones.id_fide,
documento_soc as c01_cuit,
IIF(len(cuit_int)=11,cuit_int, cuit_integrante) as c01_cuit_soc,
cargos.car_codigo as car_codigo,
convert(char(7),fecha_publicacion) as c04_periodo_desde
from sociedades_constituciones
inner join cargos -- Solo va a pasar cargos existentes
on cargos.car_nombre = ltrim(rtrim(replace(replace(sociedades_constituciones.cargo,'CESIONARIO',''),' - ',' ')))
or cargos.car_nombre_2 = ltrim(rtrim(replace(replace(sociedades_constituciones.cargo,'CESIONARIO',''),' - ',' ')))
or cargos.car_nombre_3 = ltrim(rtrim(replace(replace(sociedades_constituciones.cargo,'CESIONARIO',''),' - ',' ')))
or cargos.car_nombre_4 = ltrim(rtrim(replace(replace(sociedades_constituciones.cargo,'CESIONARIO',''),' - ',' ')))
or cargos.car_nombre_5 = ltrim(rtrim(replace(replace(sociedades_constituciones.cargo,'CESIONARIO',''),' - ',' ')))
where documento_soc like '3__________'
and (cuit_int like '2__________' or cuit_integrante like '2__________')
and isnull(cargo,'') like 'CESIONARIO%'
and procesado_socios is null
order by sociedades_constituciones.id_fide desc
OPEN bn
Fetch next from bn INTO
@id,
@c01_cuit,
@c01_cuit_soc,
@car_codigo,
@c04_periodo_desde
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
set @cant = 0
set @cant = (select COUNT(*) from socios
where c01_cuit = @c01_cuit
and c01_cuit_soc = @c01_cuit_soc
and visible = 1)
if (@cant > 0)
begin
update socios
set visible = 0,
modified = GETDATE(),
modified_by = '1'
where c01_cuit = @c01_cuit
and c01_cuit_soc = @c01_cuit_soc
end
insert into socios
(
c01_cuit,
c01_cuit_soc,
car_codigo,
c04_ultimo,
visible,
c04_periodo_desde,
created,
created_by)
values
(
@c01_cuit,
@c01_cuit_soc,
@car_codigo,
'S',
'1',
@c04_periodo_desde,
GETDATE(),
'1')
update sociedades_constituciones
set procesado_socios = 'S'
where id_fide = @id
Fetch next from bn INTO
@id,
@c01_cuit,
@c01_cuit_soc,
@car_codigo,
@c04_periodo_desde
END
CLOSE bn
DEALLOCATE bn
END
GO