I have a table that contains a list of public holidays for the current year. Now, the working days here are Monday-Saturday. So, I am trying to link the annual holidays table with my query in such a way that I get the list of Working Days for a given interval(Year, Month, Week etc) I have the code that gives me working days including Saturday but I am not able to subtract(link) the annual holidays.
Code for getting working days:
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = '2017-12-01 10:00:00.000'
SET @EndDate = '2017-12-31 00:00:00.000'
SELECT
(DATEDIFF(dd, @StartDate, @EndDate) + 1)
-(DATEDIFF(wk, @StartDate, @EndDate))
-(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END) AS WorkingDays
The table AnnualHolidays
has the layout :
Id Date Description
----------- ----------------------- -------------------
50 2017-10-21 00:00:00.000 Holiday 1
49 2017-10-20 00:00:00.000 Holiday 2
So, Is there any way that I can subtract the annual holiday coming in the Interval of @StartDate
and @EndDate
such that I can get the actual Working days of the specified interval