Tuesday, 26 January 2021

SQL to find the Next Working Day and skip the Weekend. | SQL DB2

An example of Db2-SQL to find the next working day and skip the weekend. In this example Friday and Saturday both are weekends.

SELECT
     sysdate AS current_date
    ,DAYNAME (sysdate) current_day
    ,sysdate + 3    AS come_after_3_days
    ,DAYNAME (sysdate+3) oh_after_3_is_friday
    ,decode(DAYNAME (sysdate + 3)
            ,'Friday',(sysdate + 3) + 2
            ,'Saturday',(sysdate + 3) + 1
            ,(sysdate + 3)
           ) so_the_nextworkday_is
    ,dayname(decode(DAYNAME (sysdate + 3)
                    ,'Friday',(sysdate + 3) + 2
                    ,'Saturday',(sysdate + 3) + 1
                    ,(sysdate + 3)
                    ) 
            ) AS so_the_nextworkday_is_sunday
  FROM
    sysibm.sysdummy1

No comments:

Post a Comment