久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 SQL Server 中獲取工作日

Get working days in SQL Server(在 SQL Server 中獲取工作日)
本文介紹了在 SQL Server 中獲取工作日的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我之前已經發布過這個問題,但我想我沒有像我應該的那樣清楚.我想計算兩個日期之間的差異,比如 2018/01/012018/01/31.

I have posted this problem ago but I guess I wasn't able to be as clear as I should have. I want to calculate difference between 2 dates let's say 2018/01/01 and 2018/01/31.

我有一個表 Calendar ,它存儲哪一天是假期,什么不是.我將周日和周六標記為假期,并想計算剩余的工作日應該是 23.

I have a table Calendar which is storing what day is a holiday and what is not. I am marking Sunday and Saturday as holidays, and want to calculate the working days remaining which should be 23.

但實際上問題是我也可以將星期日標記為假期而不是星期六.

But what actually the problem is that I can also mark Sunday as holiday and not Saturday.

這就是我也想使用這張表的原因.我看到很多解決方案給了我 23 個結果,因為他們將周日和周六標記為假期,這也很好,但我也希望它使用這張表.

That's why I want to use this table as well. I see so many solutions that are giving me 23 result because they are marking Sunday and Saturday as holiday which is fine too but I want it to be using this table as well.

我嘗試了很多,但我確定我哪里出錯了.也許現在有人可以提供幫助.

I tried much but I'm sure where I am going wrong. Maybe somebody can help now.

桌子是這樣的

CREATE TABLE Calendar
(
    Day Varchar(25), --name of the day i.e Sunday, Saturday
    IsOffDay Binary  --1 for Yes and 0 for False
)

因此,如果我將周六和周日標記為假期,結果應該是 23 天,但如果我只將周日標記為假期并使周六不活動,那么結果應該是 27 天

So if I mark Saturday and Sunday as holiday the result should be 23 days but if I only mark Sunday as holiday and make Saturday inactive then it should be 27 days

一位伙伴說可能重復的提議解決方案是將周六和周日作為假期,但我不希望它被硬編碼或您說什么.

The proposed solution that one mate says is possible duplicate is getting Saturday and Sunday as holiday but I don't want that to be hard coded or whatever you say.

推薦答案

試試這個查詢.

你的桌子:

 CREATE TABLE #Calendar
    ([Day] Varchar(25), --name of the day i.e Sunday, Saturday
     IsOffDay BIT  --1 for Yes and 0 for False
     )

    INSERT INTO #Calendar ([Day],IsOffDay)
    SELECT 'Sunday',1  union
    SELECT 'Saturday',0

查詢

DECLARE @STARTDATE  DATE='2018-01-01',@ENDDATE  DATE='2018-01-31'

;WITH CTE AS (
SELECT @STARTDATE  AS STARTDATE
UNION ALL
select DATEADD(D,1,STARTDATE) 
FROM CTE
WHERE STARTDATE <@ENDDATE
)
,WORKINGDAYS AS (
SELECT STARTDATE,DATENAME(DW,STARTDATE)WEEKDAYS,C1.Day AS isweekend
FROM CTE c
left JOIN #Calendar C1 ON DATENAME(DW,STARTDATE)=C1.Day AND C1.IsOffDay=1
)

SELECT COUNT(WEEKDAYS)as WORKINGDAYS FROM WORKINGDAYS WHERE isweekend is null

注意:上述查詢為您提供 Working Days =27 .如果您希望星期六作為假期更新日歷表 IsOffDay=1 where [Day]='星期六'然后給你工作日=23

Note: The above query gives you Working Days =27 .If you want saturday as holiday Update Calendar table IsOffDay=1 where [Day]='Saturday' then gives you Working Days =23

這篇關于在 SQL Server 中獲取工作日的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 午夜精品在线观看 | 91久久精品一区二区二区 | 国产视频在线观看一区二区三区 | 国产一区二区三区在线 | 国产精品亚洲二区 | 久久久久亚洲av毛片大全 | 91免费在线 | 欧美伊人久久久久久久久影院 | 午夜激情免费视频 | 国产目拍亚洲精品99久久精品 | 91免费观看国产 | 亚洲一区亚洲二区 | 最新中文字幕 | 国产一区二区电影网 | 美女视频黄色的 | 国产女人与拘做视频免费 | 中文字幕乱码一区二区三区 | 成人在线中文字幕 | 蜜桃视频在线观看免费视频网站www | 中文字幕在线看人 | 精品伦精品一区二区三区视频 | 爱高潮www亚洲精品 中文字幕免费视频 | 欧美不卡一区二区三区 | 久久精品久久久 | 国产成人精品免高潮在线观看 | 成人在线视频网站 | 国产1区 | 成人性生交大片免费看r链接 | 91国自产 | 色爱综合网 | 国产高清无av久久 | 午夜极品 | 激情六月丁香婷婷 | 毛片在线看看 | 精品久久网 | 国产小u女发育末成年 | 视频在线一区二区 | 国产精品一卡 | 蜜桃视频在线观看免费视频网站www | 久久久精品一区 | 亚洲国产精品久久久 |