首页 > 解决方案 > 通过给定的 SLA 时间范围和营业时间计算到期日期时间的 SQL 函数

问题描述

我需要帮助来创建一个能够计算业务运营时间内给定 SLA 时间范围(小时)的截止日期的函数

在这里找到可能的解决方案:使用营业时间和假期计算截止日期,但我无法将建议转换为函数。

功能: fn_GetDueDate (@SLAStart datetime, @SLATarget int)

用于计算 DueDate 的变量:

Business Start time (weekday) = 8am
Business End time (weekday) = 9pm
Business Start time (weekends & some public holidays) = 10am
Business Start time (weekends & some public holidays) = 5pm

我有一个带有日期和描述的假期表,如果需要,我可以添加列

预期结果:

1. IF     
@SLAStart = 2021-08-13 19:30:00.000 (friday, 7:30 PM - operations 8am-9pm)
@SLATarget = 3 hours
fn_GetDueDate RETURNS = 2021-08-14 10:00:00.000 (saturday, 11:30 AM - operations 10am-5pm)

2. @SLAStart = 2021-08-15 15:57:00.000 (saturday, 3:57 PM - operations 10am-5pm)
@SLATarget = 2 hours
fn_GetDueDate RETURNS = 2021-08-16 08:57:00.000 (monday, 08:57 AM - operations 8am-9pm)

标签: sqlfunctionsql-function

解决方案


推荐阅读