Find Weekdays Between Two Dates (SQL Function-UDF)

Following user defined function returns number of weekdays between two dates specified. This function excludes the dates which are passed as input params. It excludes Saturday and Sunday as they are weekends.
CREATE FUNCTION dbo.spDBA_GetWeekDays( @StartDate datetime,@EndDate datetime )RETURNS INT AS
BEGIN
DECLARE @WorkDays INT,
@FirstPart INT
DECLARE @FirstNum INT, @TotalDays INT
DECLARE @LastNum INT, @LastPart INT
IF (DATEDIFF(DAY, @StartDate, @EndDate) 0)
THEN @LastPart - 1ELSE 0
END
SELECT @WorkDays = @WorkDays * 5 + @FirstNum + @LastNum
END
RETURN ( @WorkDays )END
GO

This function can be used as
SELECT dbo.spDBA_GetWeekDays (‘10/10/2008′, ‘11/22/2008′)
GO

Hiç yorum yok:

Visual Studio 2017'de Devexpress 17.2.5 Toolbox görünmüyor

Visual Studio 2017 Toolbox'ı üzerinde Developer Express componentlerini göremiyorsanız aşağıdaki komutu çalıştırmak işini görecektir. (...