I am using this sql code to count the working days without weekends and holidays. How can I subtract the birthday date if it's between the sDate and eDate for every event type different from 'B' for birthday?
SELECT
evt.[Name],
evt.[type],
evt.sDate,
evt.eDate,
DATEDIFF(DD, evt.sDate, evt.eDate) + 1
- (DATEDIFF(WK, evt.sDate, evt.eDate) * 2)
- CASE WHEN DATEPART(DW, evt.sDate) = 1 THEN 1 ELSE 0 END
+ CASE WHEN DATEPART(DW, evt.eDate) = 1 THEN 1 ELSE 0 END
- (SELECT COUNT(*) FROM tblHolidays AS h WHERE h.Data BETWEEN evt.sDate AND evt.eDate) as date_diff
-- subtract birthday date if between sDate and eDate
FROM tblEvents AS evt
WHERE YEAR(sDate) = YEAR(getdate())
AND MONTH(sDate) = 12
ORDER BY evt.[Name]
Table of Events: The column Birthday shows if the value should be subtracted from date_diff