We have a table that contains resources and the days' that they work. For example, one person could work Monday - Friday but another could only work two days of that week. Here is the data:
WorkOnSunday WorkOnMonday WorkOnTuesday WorkOnWednesday WorkOnThursday WorkOnFriday WorkOnSaturday
--------------------------------------------------------------------------------------------------------------
0 1 1 1 1 1 0
0 0 1 1 0 0 0
(apologies for the lack of formatting but screenshots wont upload through our damn proxy.)
So the question is, how do I get the amount of days worked in a month using the data above? (Holidays are the next stage. I'm attempting to get a hold of the holidays table that we apparently have)
Here is what I have so far:
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = '2017/12/01'
SET @EndDate = '2018/01/01'
SELECT
(DATEDIFF(dd, @StartDate, @EndDate))
-(DATEDIFF(wk, @StartDate, @EndDate) * 2)
-(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)
-(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
This gives me the correct amount of weekdays in the month