sql working days holidays

前端 未结 3 676
攒了一身酷
攒了一身酷 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:49

    Assuming we have a DateTable with columns actual_date (date) and is_holiday (bit) , containing all dates and where all workdays have is_holiday=0:

    SELECT actual_date from 
    (
        SELECT actual_date, ROW_NUMBER() OVER(ORDER BY actual_date) AS Row 
        FROM DateTable
        WHERE is_holiday= 0 and actual_date > '2013-12-01'
    ) X
    WHERE row = 65
    

    This will find 2013-12-01 plus 65 workdays, skipping holidays.

提交回复
热议问题