• The code attempts to subtract weekends, holidays...

    I would do that part with a Calendar table... then you need pretty much ZERO logic for it.

    WHERE Calendar.IsWeekend = False AND Calendar.IsHoliday=False...