Calculating 'Number of Working days excluding weekend' using WHILE

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 932
--No. of Working days
DECLARE @StartDate DATETIME
DECLARE @count int=0
DECLARE @EndDate DATETIME
SET @StartDate = '2014-08-27'
SET @EndDate = '2014-09-09'
While ( @StartDate <= @EndDate)
BEGIN
If ( DATENAME(DW, @startdate ) NOT IN ('Saturday', 'sunday'))
SET @count = @count + 1;
SET @StartDate = @StartDate +1;
END
SELECT @count

Comments or Responses

Login to post response