获取两个日期之间的工作日数(星期日,星期一,星期二)SQL

获取两个日期之间的工作日数(星期日,星期一,星期二)SQL,第1张

获取两个日期之间的工作日数星期日,星期一,星期二)SQL

鉴于我 认为 您正在尝试获得的结果,应该这样做:

SET DATEFIRST 1DECLARE    @start_date DATETIME,    @end_date DATETIMESET @start_date = '2011-07-11'SET @end_date = '2011-07-22';WITH Days_Of_The_Week AS (    SELECt 1 AS day_number, 'Monday' AS day_name UNIOn ALL    SELECT 2 AS day_number, 'Tuesday' AS day_name UNIOn ALL    SELECT 3 AS day_number, 'Wednesday' AS day_name UNIOn ALL    SELECT 4 AS day_number, 'Thursday' AS day_name UNIOn ALL    SELECT 5 AS day_number, 'Friday' AS day_name UNIOn ALL    SELECT 6 AS day_number, 'Saturday' AS day_name UNIOn ALL    SELECT 7 AS day_number, 'Sunday' AS day_name)SELECT    day_name,    1 + DATEDIFF(wk, @start_date, @end_date) -        CASE WHEN DATEPART(weekday, @start_date) > day_number THEN 1 ELSE 0 END -        CASE WHEN DATEPART(weekday, @end_date)   < day_number THEN 1 ELSE 0 ENDFROM    Days_Of_The_Week


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5640816.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存