sql working days holidays

前端 未结 3 686
攒了一身酷
攒了一身酷 2021-01-16 10:07

I\'ve seen different version of this kind of function for other coding languages (Python, jQuery, etc.) but not for SQL. I have a procedure that needs to have a date calcul

3条回答
  •  盖世英雄少女心
    2021-01-16 10:39

    I wrote a SQL function years ago to build a dynamic holiday table as a table function. The link is below:

    http://www.joebooth-consulting.com/sqlServer/sqlServer.html#CalendFunc

    Hope it helps...

    You can access the table function (or your own holiday table) to determine number of holidays via a SQL statement like below

    SELECT count(*) FROM holiday_date(2013)
    WHERE holiday_date BETWEEN @fromDate AND @toDate
    

    then add the count to the returned date using dateAdd().

    If you might have holidays that fall on a weekend, add the following to the WHERE clause

       AND DatePart(dw, Holiday_date) != 1) and (DatePart(dw, holiday_date) != 7)
    

提交回复
热议问题