07/02/2006, 16:57
|
| Colaborador | | Fecha de Ingreso: abril-2003
Mensajes: 12.106
Antigüedad: 21 años, 8 meses Puntos: 25 | |
Código:
/********************************************************************************************
**** returns date after given number of working days
**** uses function fNextWorkingDay
****
**********************************************************************************************/
CREATE FUNCTION fAddWorkingDay (@Start datetime, @NumOfDays integer)
RETURNS datetime
AS
BEGIN
DECLARE @NextDay datetime
DECLARE @Counter int
IF @NumOfDays>0
BEGIN
SET @Counter=1
-- Drop the time part and initialize the Return Variable
SET @NextDay=CONVERT(datetime ,(CONVERT(char(10),@Start,102)),102 )
WHILE @Counter <= @NumOfDays
BEGIN
SET @NextDay = dbo.fNextWorkingDay(@NextDay)
SET @Counter=@Counter+1
END
END
ELSE
BEGIN
SET @Counter=ABS(@NumOfDays)
-- Drop the time part and initialize the Return Variable
SET @NextDay=CONVERT(datetime ,(CONVERT(char(10),@Start,102)),102 )
WHILE @Counter>0
BEGIN
SET @NextDay = dbo.fPreviousWorkingDay(@NextDay)
SET @Counter=@Counter-1
END
END
RETURN @NextDay
END
http://www.sql-server-performance.co...TOPIC_ID=10395
__________________ "El hombre, en su orgullo, creó a Dios a su imagen y semejanza."Friedrich Nietzsche |