• ChrisM@Work - Thursday, October 19, 2017 9:31 AM

    Jason A. Long - Wednesday, October 18, 2017 6:00 PM

    I have to believe that someone here has the magic go-fast this thing is missing... :crying:

    Jason, I don't think you'll get around what looks like a Cartesian join, because for each date pair, you have to count the rows between them in your holiday table.
    You can however simplify the weekdays calculation, like this:

    SELECT

    WorkingDays = (DATEDIFF(dd, @BegDate, @EndDate) + 1)

    - (DATEDIFF(wk, @BegDate, @EndDate) * 2)

    - (CASE WHEN DATENAME(dw, @BegDate) = 'Sunday' THEN 1 ELSE 0 END)

    - (CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)

    I already did... I just haven't had the chance to finish testing. Plus, I'm really curious to see what Jeff comes up with.