Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_Cuit | varchar | 20 | |
| @cant_meses | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
[obtener_empleados_nuevo] '30641368977'
[obtener_empleados_nuevo] '30627393713'
[obtener_empleados] '30622216309'
[obtener_empleados] '30641368977'
[obtener_empleados] '30709026336'
exec obtener_empleados '30708934409'
select periodo, count(distinct cuil) from empleados where cuit = '30708934409'
group by periodo
*/
CREATE OR ALTER PROCEDURE dbo.obtener_empleados
@p_Cuit varchar(20), @cant_meses int = 6
AS
BEGIN
SET NOCOUNT ON;
declare @periodo int,
@cantidad_hombres decimal(15,2),
@cantidad_mujeres decimal(15,2),
@hombres2 decimal(15,2),
@mujeres2 decimal(15,2),
@total decimal(15,2),
@fecha varchar(10),
@fecha_formateada varchar(10),
@total2 decimal
declare @ultimo_mes_empleados date,
@mes_empleados date,
@periodo_empleados_desde int,
@periodo_empleados_hasta int,
@cantidad int
set @ultimo_mes_empleados = (select max(fuentes_procesadas.fecha_informacion) from fuentes_procesadas where fuente = 'empleados')
set @mes_empleados = '2020-10-01'--DATEADD(M,-2,@ultimo_mes_empleados)
/* 28/06/2022:
-- que se le mande la cantidad de meses a tomar, como parĂ¡metro (default 2) */
--set @mes_empleados = DATEADD(M,-2,@ultimo_mes_empleados)
set @cant_meses = @cant_meses * (-1)
set @mes_empleados = DATEADD(M,@cant_meses,@ultimo_mes_empleados)
/* ----------------------------------------------------------------*/
set @periodo_empleados_desde = convert(int,substring(convert(char,@mes_empleados),3,2)+substring(convert(char,@mes_empleados),6,2))
set @periodo_empleados_hasta = convert(int,substring(convert(char,@ultimo_mes_empleados),3,2)+substring(convert(char,@ultimo_mes_empleados),6,2))
/*
set @periodo = (select substring(replace(MAX(convert(char(7),fecha_informacion)),'-',''),3,4) from fuentes_procesadas where fuente = 'empleados')
set @fecha_formateada = @periodo
set @fecha_formateada = rtrim(convert(char(2), convert(int,SUBSTRING(@fecha_formateada,3,2))))+'/20'+SUBSTRING(@fecha_formateada,1,2)
*/
begin
-- Busco de los ultimos 3 meses, que mes trajo mas empleados
select top 1 @periodo = periodo, @cantidad = COUNT(distinct cuil)
from empleados
where empleados.cuit = @p_cuit
and periodo between @periodo_empleados_desde and @periodo_empleados_hasta
group by periodo
order by 2 desc, 1 desc
set @fecha_formateada = @periodo
set @fecha_formateada = rtrim(convert(char(2), convert(int,SUBSTRING(@fecha_formateada,3,2))))+'/20'+SUBSTRING(@fecha_formateada,1,2)
/*
select @cantidad_hombres = count(distinct cuil) from empleados where (CharIndex('20', empleados.cuil) = 1) and empleados.cuit = @p_Cuit and periodo = @periodo --and fechapres = @fecha
select @cantidad_mujeres = count(distinct cuil) from empleados where (CharIndex('27', empleados.cuil) = 1) and empleados.cuit = @p_Cuit and periodo = @periodo --and fechapres = @fecha
select @hombres2 = count(distinct cuil) from empleados where (CharIndex('23', empleados.cuil) = 1) and empleados.cuit = @p_Cuit and periodo = @periodo --and fechapres = @fecha
select @mujeres2 = count(distinct cuil) from empleados where (CharIndex('24', empleados.cuil) = 1) and empleados.cuit = @p_Cuit and periodo = @periodo --and fechapres = @fecha
*/
set @hombres2 = 0
set @mujeres2 = 0
-- Chanchada: Si son mas de 100.000 empleados, no buscamos sexo en padrones (tomamos cuil 27 mujeres, resto hombres)
if (@cantidad > 100000)
BEGIN
set @total = @cantidad
select @cantidad_mujeres = count(distinct cuil) from empleados
where empleados.cuit = @p_Cuit and periodo = @periodo
and cuil like '27%'
set @cantidad_hombres = @cantidad - @cantidad_mujeres
END
ELSE
BEGIN
set @cantidad_hombres = 0
/*select @cantidad_hombres = count(distinct cuil) from empleados
inner join padrones on identificacion = cuil and sexo = 'M'
where empleados.cuit = @p_Cuit and periodo = @periodo --and fechapres = @fecha
*/
select @hombres2 = count(distinct cuil) from empleados
-- left join padrones on identificacion = cuil
where ((CharIndex('23', empleados.cuil)) = 1 or (CharIndex('20', empleados.cuil)) = 1)
and empleados.cuit = @p_Cuit
and periodo = @periodo --and fechapres = @fecha
--and isnull(sexo,'') not in ('F','M')
/*-- Para no consumir tiempo buscando cantidad de mujeres, tomamos que las mujeres es el total - los hombres
select @cantidad_mujeres = count(distinct cuil) from empleados
inner join padrones on identificacion = cuil and sexo = 'F'
where empleados.cuit = @p_Cuit and periodo = @periodo --and fechapres = @fecha
select @mujeres2 = count(distinct cuil) from empleados
left join padrones on identificacion = cuil
where ((CharIndex('24', empleados.cuil)) = 1 or (CharIndex('27', empleados.cuil)) = 1)
and empleados.cuit = @p_Cuit
and periodo = @periodo --and fechapres = @fecha
and isnull(sexo,'') not in ('F','M')
set @total = @cantidad_hombres + @cantidad_mujeres + @hombres2 + @mujeres2
*/
set @total = @cantidad
set @cantidad_mujeres = @total - (@cantidad_hombres + @hombres2)
END
--select @periodo as periodo, @total total, @hombres2 hombres, @cantidad_mujeres mujeres
declare @multi int = 0
if len(convert(int,@total)) = 1
begin
set @multi = 1
end
if len(convert(int,@total)) = 2
begin
set @multi = 10
end
if len(convert(int,@total)) = 3
begin
set @multi = 10
end
if len(convert(int,@total)) = 4
begin
set @multi = 100
end
if len(convert(int,@total)) = 5
begin
set @multi = 1000
end
if len(convert(int,@total)) = 6
begin
set @multi = 10000
end
if len(convert(int,@total)) = 7
begin
set @multi = 10000
end
end
if(@total> 0)
--chanchada
if(@p_Cuit = '30641368977')
begin
select ceiling(((@cantidad_hombres+@hombres2)*100)/@total) as cantidad_hombres,
floor(((@cantidad_mujeres+@mujeres2)*100)/@total) as cantidad_mujeres,
50 as total,
@fecha_formateada as fecha
end
else
begin
select ceiling(((@cantidad_hombres+@hombres2)*100)/@total) as cantidad_hombres,
floor(((@cantidad_mujeres+@mujeres2)*100)/@total) as cantidad_mujeres,
/*floor((convert(money,@total)/@multi))*@multi as total, cambiado 31-03-2021 AGB*/
ceiling((convert(money,@total)/@multi))*@multi as total,
@fecha_formateada as fecha
end
end
GO
GO
/*
[obtener_empleados_nuevo] '30641368977'
[obtener_empleados_nuevo] '30627393713'
[obtener_empleados] '30622216309'
[obtener_empleados] '30641368977'
[obtener_empleados] '30709026336'
exec obtener_empleados '30708934409'
select periodo, count(distinct cuil) from empleados where cuit = '30708934409'
group by periodo
*/
CREATE OR ALTER PROCEDURE dbo.obtener_empleados
@p_Cuit varchar(20), @cant_meses int = 6
AS
BEGIN
SET NOCOUNT ON;
declare @periodo int,
@cantidad_hombres decimal(15,2),
@cantidad_mujeres decimal(15,2),
@hombres2 decimal(15,2),
@mujeres2 decimal(15,2),
@total decimal(15,2),
@fecha varchar(10),
@fecha_formateada varchar(10),
@total2 decimal
declare @ultimo_mes_empleados date,
@mes_empleados date,
@periodo_empleados_desde int,
@periodo_empleados_hasta int,
@cantidad int
set @ultimo_mes_empleados = (select max(fuentes_procesadas.fecha_informacion) from fuentes_procesadas where fuente = 'empleados')
set @mes_empleados = '2020-10-01'--DATEADD(M,-2,@ultimo_mes_empleados)
/* 28/06/2022:
-- que se le mande la cantidad de meses a tomar, como parĂ¡metro (default 2) */
--set @mes_empleados = DATEADD(M,-2,@ultimo_mes_empleados)
set @cant_meses = @cant_meses * (-1)
set @mes_empleados = DATEADD(M,@cant_meses,@ultimo_mes_empleados)
/* ----------------------------------------------------------------*/
set @periodo_empleados_desde = convert(int,substring(convert(char,@mes_empleados),3,2)+substring(convert(char,@mes_empleados),6,2))
set @periodo_empleados_hasta = convert(int,substring(convert(char,@ultimo_mes_empleados),3,2)+substring(convert(char,@ultimo_mes_empleados),6,2))
/*
set @periodo = (select substring(replace(MAX(convert(char(7),fecha_informacion)),'-',''),3,4) from fuentes_procesadas where fuente = 'empleados')
set @fecha_formateada = @periodo
set @fecha_formateada = rtrim(convert(char(2), convert(int,SUBSTRING(@fecha_formateada,3,2))))+'/20'+SUBSTRING(@fecha_formateada,1,2)
*/
begin
-- Busco de los ultimos 3 meses, que mes trajo mas empleados
select top 1 @periodo = periodo, @cantidad = COUNT(distinct cuil)
from empleados
where empleados.cuit = @p_cuit
and periodo between @periodo_empleados_desde and @periodo_empleados_hasta
group by periodo
order by 2 desc, 1 desc
set @fecha_formateada = @periodo
set @fecha_formateada = rtrim(convert(char(2), convert(int,SUBSTRING(@fecha_formateada,3,2))))+'/20'+SUBSTRING(@fecha_formateada,1,2)
/*
select @cantidad_hombres = count(distinct cuil) from empleados where (CharIndex('20', empleados.cuil) = 1) and empleados.cuit = @p_Cuit and periodo = @periodo --and fechapres = @fecha
select @cantidad_mujeres = count(distinct cuil) from empleados where (CharIndex('27', empleados.cuil) = 1) and empleados.cuit = @p_Cuit and periodo = @periodo --and fechapres = @fecha
select @hombres2 = count(distinct cuil) from empleados where (CharIndex('23', empleados.cuil) = 1) and empleados.cuit = @p_Cuit and periodo = @periodo --and fechapres = @fecha
select @mujeres2 = count(distinct cuil) from empleados where (CharIndex('24', empleados.cuil) = 1) and empleados.cuit = @p_Cuit and periodo = @periodo --and fechapres = @fecha
*/
set @hombres2 = 0
set @mujeres2 = 0
-- Chanchada: Si son mas de 100.000 empleados, no buscamos sexo en padrones (tomamos cuil 27 mujeres, resto hombres)
if (@cantidad > 100000)
BEGIN
set @total = @cantidad
select @cantidad_mujeres = count(distinct cuil) from empleados
where empleados.cuit = @p_Cuit and periodo = @periodo
and cuil like '27%'
set @cantidad_hombres = @cantidad - @cantidad_mujeres
END
ELSE
BEGIN
set @cantidad_hombres = 0
/*select @cantidad_hombres = count(distinct cuil) from empleados
inner join padrones on identificacion = cuil and sexo = 'M'
where empleados.cuit = @p_Cuit and periodo = @periodo --and fechapres = @fecha
*/
select @hombres2 = count(distinct cuil) from empleados
-- left join padrones on identificacion = cuil
where ((CharIndex('23', empleados.cuil)) = 1 or (CharIndex('20', empleados.cuil)) = 1)
and empleados.cuit = @p_Cuit
and periodo = @periodo --and fechapres = @fecha
--and isnull(sexo,'') not in ('F','M')
/*-- Para no consumir tiempo buscando cantidad de mujeres, tomamos que las mujeres es el total - los hombres
select @cantidad_mujeres = count(distinct cuil) from empleados
inner join padrones on identificacion = cuil and sexo = 'F'
where empleados.cuit = @p_Cuit and periodo = @periodo --and fechapres = @fecha
select @mujeres2 = count(distinct cuil) from empleados
left join padrones on identificacion = cuil
where ((CharIndex('24', empleados.cuil)) = 1 or (CharIndex('27', empleados.cuil)) = 1)
and empleados.cuit = @p_Cuit
and periodo = @periodo --and fechapres = @fecha
and isnull(sexo,'') not in ('F','M')
set @total = @cantidad_hombres + @cantidad_mujeres + @hombres2 + @mujeres2
*/
set @total = @cantidad
set @cantidad_mujeres = @total - (@cantidad_hombres + @hombres2)
END
--select @periodo as periodo, @total total, @hombres2 hombres, @cantidad_mujeres mujeres
declare @multi int = 0
if len(convert(int,@total)) = 1
begin
set @multi = 1
end
if len(convert(int,@total)) = 2
begin
set @multi = 10
end
if len(convert(int,@total)) = 3
begin
set @multi = 10
end
if len(convert(int,@total)) = 4
begin
set @multi = 100
end
if len(convert(int,@total)) = 5
begin
set @multi = 1000
end
if len(convert(int,@total)) = 6
begin
set @multi = 10000
end
if len(convert(int,@total)) = 7
begin
set @multi = 10000
end
end
if(@total> 0)
--chanchada
if(@p_Cuit = '30641368977')
begin
select ceiling(((@cantidad_hombres+@hombres2)*100)/@total) as cantidad_hombres,
floor(((@cantidad_mujeres+@mujeres2)*100)/@total) as cantidad_mujeres,
50 as total,
@fecha_formateada as fecha
end
else
begin
select ceiling(((@cantidad_hombres+@hombres2)*100)/@total) as cantidad_hombres,
floor(((@cantidad_mujeres+@mujeres2)*100)/@total) as cantidad_mujeres,
/*floor((convert(money,@total)/@multi))*@multi as total, cambiado 31-03-2021 AGB*/
ceiling((convert(money,@total)/@multi))*@multi as total,
@fecha_formateada as fecha
end
end
GO
Depends On
2Used By
13- dbo.LN_dashboard_cliente
- dbo.LN_dashboard_cliente_0822
- dbo.LN_dashboard_cliente_2024
- dbo.LN_dashboard_cliente_21-08-2022-AGB
- dbo.LN_dashboard_cliente_AB
- dbo.LN_dashboard_cliente_AGB
- dbo.LN_dashboard_cliente_MIS
- dbo.LN_dashboard_cliente_ppp
- dbo.sp_procesos_cuit_enrichment
- dbo.sp_procesos_cuit_enrichment_simples
- dbo.sp_procesos_cuit_enrichment_simples_filtros
- dbo.sp_procesos_nivel_socio_economico
- dbo.sp_REPROCESO_cuit_enrichment