Select dbo.WorkDays()
Tame Those Strings - Using SUBSTRING
In this article by Steve Jones, he shows you how to manipulate strings.
2004-04-05
17,655 reads
Select dbo.WorkDays()
Create FUNCTION [dbo].[WorkDays] ( -- Add the parameters for the function here ) RETURNS int AS BEGIN -- Declare the return variable here DECLARE @WorkDays int -- Add the T-SQL statements to compute the return value here SELECT @WorkDays = (SELECT COUNT(number+1) FROM master..spt_values WHERE type='p' AND number <datepart(dd, DateAdd(day,-1,DateAdd(Month,1,DateAdd(Month, DateDiff(Month, 0, GETDATE()),0)))) AND datename(WEEKDAY,DateAdd(Month, DateDiff(Month, 0, GetDate()), number) ) not in ('Saturday','Sunday') AND number+1 NOT IN(SELECT DATEPART(DAY,HOLIDAY) FROM HOLIDAYS WHERE DATEPART(MONTH,HOLIDAY ) = DATEPART(MONTH,GETDATE()) AND DATEPART(YEAR,HOLIDAY) = DATEPART(YEAR,GETDATE()))) -- Return the result of the function RETURN @WorkDays END