Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
1| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_Cuit | varchar | 20 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
[obtener_empleados_nuevo] '30641368977'
[obtener_empleados_nuevo] '30627393713'
[obtener_empleados_nuevo] '30622216309'
[obtener_empleados_nuevo] '30627393713'
[obtener_empleados_nuevo] '20163203945'
*/
CREATE OR ALTER PROCEDURE dbo.obtener_empleados_nuevo
@p_Cuit varchar(20)
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 = DATEADD(M,-2,@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
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
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,
@fecha_formateada as fecha
end
end
GO
GO
/*
[obtener_empleados_nuevo] '30641368977'
[obtener_empleados_nuevo] '30627393713'
[obtener_empleados_nuevo] '30622216309'
[obtener_empleados_nuevo] '30627393713'
[obtener_empleados_nuevo] '20163203945'
*/
CREATE OR ALTER PROCEDURE dbo.obtener_empleados_nuevo
@p_Cuit varchar(20)
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 = DATEADD(M,-2,@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
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
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,
@fecha_formateada as fecha
end
end
GO
Depends On
3Used By
No items found