Animation calculation workday

Source: Internet
Author: User

Whether the table is set to workday. (if it is set to a non-workday for a holiday, talbe sets whether the day is a workday)
The input date must be a business day.

ALTER function [dbo]. [fn_workdayadd] (@ date datetime, @ days int)
Returns datetime -- nvarchar (100)
As
Begin

Declare @ I int -- computing work days
Set @ I = 1

Declare @ flag nvarchar (10) -- whether it is a working day

WHILE (@ I <= @ days)
BEGIN
If exists (SELECT top 1 flag FROM dbo. BCC_Admin_WorkDay
Where flag = 'y' and convert (nvarchar (10), Date, 120) = convert (nvarchar (10), @ date + 1,120) -- workday
Begin
Set @ I = @ I + 1
Set @ date = @ date + 1
Set @ flag = 'y'
End
Else
Begin
Set @ date = @ date + 1
Set @ flag = 'n'
End
CONTINUE
END

-- The last day is the work day. check whether there is any
While exists (SELECT top 1 flag FROM dbo. BCC_Admin_WorkDay where convert (nvarchar (10), Date, 120) = convert (nvarchar (10), @ date + 1,120) and flag = 'n ')
Begin
Set @ date = @ date + 1
End

Return convert (nvarchar (10), @ date, 120) -- + ''+ @ flag
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.