-- DROP FUNCTION GetWorkdays
CREATE FUNCTION GetWorkdays (
@month int,
@year int
) RETURNS INT AS BEGIN
declare @result int
declare @seedDate datetime
SET @seedDate = DATEADD(YEAR, @year - 1900, 0)
SELECT @result = SUM(
CASE
WHEN DATEPART(weekday, DATEADD(d, number, @seedDate)) IN (1,7)
THEN 0
ELSE 1
END
)
from master..spt_values
where type = 'p'
and YEAR(DATEADD(d, number, @seedDate)) = YEAR(@seedDate)
and MONTH(DATEADD(d, number, @seedDate)) = @month
return @result
END
|