dbo.obtener_empleados_ant

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

CREATE OR ALTER PROCEDURE dbo.obtener_empleados_ant 
@p_Cuit varchar(20)
AS
BEGIN
       SET NOCOUNT ON;
/*    
declare @cantidad_hombres int,@cantidad_mujeres int,@hombres2 int,@mujeres2 int,@total int,@fecha varchar(4),@fecha_formateada varchar(10),@total2 decimal
*/


/*
declare @p_Cuit varchar(20) = '30547242331'

*/



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

/*
set @fecha = convert(varchar(12),(select max(fechapres) from empleados where cuit = @p_Cuit),112)

if(@fecha is not null)
begin
set @fecha_formateada = cast(datepart(MM,cast(@fecha as date)) as varchar) +'/'+ cast(DATEPART(YY,cast(@fecha as date)) as varchar)
end
*/

-- Se cambio por:
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

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

Used By

No items found