Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @cliente | int | 4 | |
| @fecha_proceso | date | 3 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.sp_procesos_nivel_socio_economico_empleados
@cliente int = '263625984',
@fecha_proceso date = '2018-08-06'
AS
BEGIN
SET NOCOUNT ON;
declare @id_padron int,
@cuit varchar(20)
declare @telefonos table ( cuit varchar(20),
telefono varchar(max))
declare @tel varchar(max)
declare @cuil varchar(20)
DECLARE C_padron CURSOR FOR
select distinct id_padron, cuit
from procesos_nivel_socio_economico_empleados a
where (select COUNT(distinct cuil) from procesos_nivel_socio_economico_empleados b
where b.cuit = a.cuit) < 5
OPEN C_Padron
FETCH NEXT FROM C_Padron INTO @id_padron,
@cuit
WHILE @@fetch_status = 0
BEGIN
--> EMPLEADOS: Datos de 5 Mayores sueldos de la nĂ³mina (cuit y datos de contacto-tel o celular)
insert into procesos_nivel_socio_economico_empleados_2
(cliente, fecha_proceso, id_padron, cuit, cuil, nombre_empleado, periodo, sueldo)
select distinct top 5 @cliente, @fecha_proceso, @id_padron,
a.cuit, a.cuil, p.nombre_persona,
'20' + SUBSTRING(convert(char(6),a.periodo),1,2) + '-' + SUBSTRING(convert(char(6),a.periodo),3,2) as periodo,
a.remimp
from empleados a
inner join padrones p on identificacion = a.cuil and p.habilitado = 1 and p.identificador in ('CUIL','CUIT')
where a.cuit = @cuit
and a.periodo = (select max(periodo) from empleados where cuit = @cuit and periodo not like '%12' and periodo not like '%06')
and a.fechapres = (select MAX(fechapres) from empleados b where b.cuit = a.cuit and b.cuil = a.cuil and b.periodo = a.periodo)
order by a.remimp desc
/*
delete from procesos_nivel_socio_economico_empleados_2
where exists (select * from procesos_nivel_socio_economico_empleados
where procesos_nivel_socio_economico_empleados.cuit = procesos_nivel_socio_economico_empleados_2.cuit
and procesos_nivel_socio_economico_empleados.cuil = procesos_nivel_socio_economico_empleados_2.cuit
and procesos_nivel_socio_economico_empleados.sueldo = procesos_nivel_socio_economico_empleados_2.sueldo)
--> Telefonos empleados
DECLARE tel_empleados CURSOR FOR
select cuil from procesos_nivel_socio_economico_empleados_2 where cliente = @cliente and fecha_proceso = @fecha_proceso and cuit = @cuit
OPEN tel_empleados
FETCH NEXT FROM tel_empleados INTO @cuil
WHILE @@fetch_status = 0
BEGIN
insert into @telefonos
exec sp_obtener_telefonos @cuil
set @tel = (select telefono from @telefonos)
delete from @telefonos
update procesos_nivel_socio_economico_empleados_2
set telefono = @tel
where cliente = @cliente and fecha_proceso = @fecha_proceso and cuit = @cuit and cuil = @cuil
END
CLOSE tel_empleados
DEALLOCATE tel_empleados
*/
FETCH NEXT FROM C_Padron INTO @id_padron,
@cuit
END
CLOSE C_Padron
DEALLOCATE C_Padron
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.sp_procesos_nivel_socio_economico_empleados
@cliente int = '263625984',
@fecha_proceso date = '2018-08-06'
AS
BEGIN
SET NOCOUNT ON;
declare @id_padron int,
@cuit varchar(20)
declare @telefonos table ( cuit varchar(20),
telefono varchar(max))
declare @tel varchar(max)
declare @cuil varchar(20)
DECLARE C_padron CURSOR FOR
select distinct id_padron, cuit
from procesos_nivel_socio_economico_empleados a
where (select COUNT(distinct cuil) from procesos_nivel_socio_economico_empleados b
where b.cuit = a.cuit) < 5
OPEN C_Padron
FETCH NEXT FROM C_Padron INTO @id_padron,
@cuit
WHILE @@fetch_status = 0
BEGIN
--> EMPLEADOS: Datos de 5 Mayores sueldos de la nĂ³mina (cuit y datos de contacto-tel o celular)
insert into procesos_nivel_socio_economico_empleados_2
(cliente, fecha_proceso, id_padron, cuit, cuil, nombre_empleado, periodo, sueldo)
select distinct top 5 @cliente, @fecha_proceso, @id_padron,
a.cuit, a.cuil, p.nombre_persona,
'20' + SUBSTRING(convert(char(6),a.periodo),1,2) + '-' + SUBSTRING(convert(char(6),a.periodo),3,2) as periodo,
a.remimp
from empleados a
inner join padrones p on identificacion = a.cuil and p.habilitado = 1 and p.identificador in ('CUIL','CUIT')
where a.cuit = @cuit
and a.periodo = (select max(periodo) from empleados where cuit = @cuit and periodo not like '%12' and periodo not like '%06')
and a.fechapres = (select MAX(fechapres) from empleados b where b.cuit = a.cuit and b.cuil = a.cuil and b.periodo = a.periodo)
order by a.remimp desc
/*
delete from procesos_nivel_socio_economico_empleados_2
where exists (select * from procesos_nivel_socio_economico_empleados
where procesos_nivel_socio_economico_empleados.cuit = procesos_nivel_socio_economico_empleados_2.cuit
and procesos_nivel_socio_economico_empleados.cuil = procesos_nivel_socio_economico_empleados_2.cuit
and procesos_nivel_socio_economico_empleados.sueldo = procesos_nivel_socio_economico_empleados_2.sueldo)
--> Telefonos empleados
DECLARE tel_empleados CURSOR FOR
select cuil from procesos_nivel_socio_economico_empleados_2 where cliente = @cliente and fecha_proceso = @fecha_proceso and cuit = @cuit
OPEN tel_empleados
FETCH NEXT FROM tel_empleados INTO @cuil
WHILE @@fetch_status = 0
BEGIN
insert into @telefonos
exec sp_obtener_telefonos @cuil
set @tel = (select telefono from @telefonos)
delete from @telefonos
update procesos_nivel_socio_economico_empleados_2
set telefono = @tel
where cliente = @cliente and fecha_proceso = @fecha_proceso and cuit = @cuit and cuil = @cuil
END
CLOSE tel_empleados
DEALLOCATE tel_empleados
*/
FETCH NEXT FROM C_Padron INTO @id_padron,
@cuit
END
CLOSE C_Padron
DEALLOCATE C_Padron
END
GO
Used By
No items found