Created
November 28, 2013 16:05
-
-
Save gepser/7694205 to your computer and use it in GitHub Desktop.
La función obtiene el tiempo laboral en segundos de un empleado en un día específico (lunes, martes, ...)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
La función obtiene el tiempo laboral en segundos de un empleado en un día específico (lunes, martes, ...). | |
Esta función trabaja sobre una tabla de horarios por empleado donde cada empleado puede tener muchos horarios por día. | |
Se asume que no hay traslapes de horarios. | |
Un ejemplo de la tabla podría ser así: | |
dia|hora_inicio|hora_fin|empleado | |
2 |08:00 |13:00 |15 | |
2 |14:00 |18:00 |15 | |
3 |08:00 |13:00 |15 | |
3 |14:00 |18:00 |15 | |
4 |07:00 |13:00 |15 --Miércoles sólo medio día | |
5 |08:00 |13:00 |15 | |
5 |14:00 |18:00 |15 | |
6 |08:00 |13:00 |15 | |
6 |14:00 |18:00 |15 | |
*/ | |
set ANSI_NULLS ON | |
set QUOTED_IDENTIFIER ON | |
GO | |
ALTER FUNCTION [dbo].[Segundos_Laborales_Dia] ( @numero_dia int, @empleado int) | |
RETURNS FLOAT | |
AS | |
BEGIN | |
DECLARE @segundos_laborales INT | |
SET @segundos_laborales = 0 | |
select @segundos_laborales = sum(datediff(s,hora_inicio,hora_fin)) | |
from tabla_horario | |
where empleado = @empleado | |
and dia = @numero_dia | |
group by dia | |
RETURN @segundos_laborales | |
END | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment