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
/*
exec obtener_empleados '30641368977'
exec obtener_empleados2 '30710593597'
*/
CREATE OR ALTER PROCEDURE dbo.obtener_empleados2
@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 int,
@periodo_empleados2 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 = convert(int,substring(convert(char,@mes_empleados),3,2)+substring(convert(char,@mes_empleados),6,2))
set @periodo_empleados2 = 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 and @periodo_empleados2
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 @total = @cantidad_hombres + @cantidad_mujeres + @hombres2 + @mujeres2
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)
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
/*
exec obtener_empleados '30641368977'
exec obtener_empleados2 '30710593597'
*/
CREATE OR ALTER PROCEDURE dbo.obtener_empleados2
@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 int,
@periodo_empleados2 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 = convert(int,substring(convert(char,@mes_empleados),3,2)+substring(convert(char,@mes_empleados),6,2))
set @periodo_empleados2 = 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 and @periodo_empleados2
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 @total = @cantidad_hombres + @cantidad_mujeres + @hombres2 + @mujeres2
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)
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
2Used By
No items found