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

如何在 SQL Server 中獲得一年中每個月的雙周日期

How to get biweekly dates per month in a year in SQL Server?(如何在 SQL Server 中獲得一年中每個月的雙周日期?)
本文介紹了如何在 SQL Server 中獲得一年中每個月的雙周日期?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

當我設置開始年份和結束年份時,我試圖生成每兩周一次的日期.

I am trying to generate biweekly dates when I set a start year and end year.

DECLARE @StartYear DATETIME
DECLARE @EndYear DATETIME

SET @StartYear = '01/01/2017'
SET @EndYear = '12/31/2017'

T-SQL 然后應該計算每兩周的日期,例如:03/15/2017 和 03/30/2017 是發薪日.

The T-SQL should then compute the biweekly dates, example: 03/15/2017 and 03/30/2017 are the paydays.

此外,如果日期落在星期六和星期日,那么它會生成到其第一個星期五的日期.

Also if the dates fall on Saturday and Sunday, then it will generate the dates to its 1st Friday.

希望有人能幫我解決這個問題.或者有人想分享他/她關于這方面的知識和公式.

Hope someone could help me with this. Or someone would like to share his/her knowledge and formula about this.

UPDATE:我的預期結果如下:

當我輸入 01/01/2017 時,它會每 15 天自動生成一次.

when I enter 01/01/2017, then it will automatically generates every 15th day.

示例:

@StartYear: 01/01/2017

結果應該是:

DatesBiweeklyPerMonthInAYear
-------------------------------
01/13/2017 (since the 15th day falls on sunday)
01/30/2017
02/15/2017
02/28/2017 (since no 30th day)

如果第 15 天落在 sun 或 sat 上,則它將落在該特定周的星期五.依此類推……直到年底.

If 15th day falls on sun or sat it will fall on Friday of that specific week. so on... until the end of the year.

這能實現嗎?或不?

謝謝!

推薦答案

您的業務規則并非 100% 明確.

your business rule is not 100% clear.

我認為正確的結果可能不止一個.

I think there can be more than one correct result.

在一個地方,它是硬編碼的,因為我想 100% 確定需求.我沒有使用游標.它只有 24 個循環.

In one place it is hard coded,because i want to be 100% sure of requirement. I am not using cursor.Its only 24 loops.

declare @StartYear datetime='2017-01-01'
declare @endYear datetime ='2017-12-31'

declare @gap int =14 --Bimonthly means gap of 14 days or 15 days whatever

;With CTE as
(
select dateadd(day,@gap, @StartYear) Bimonthly
,1 rn

UNION ALL

select  
case 

when (rn+1)%2=0 and datename(m, Bimonthly)='February' THEN
      '2017-02-28'
      when (rn+1)%2=0 and datename(m, Bimonthly)!='February' 

then dateadd(day,@gap, Bimonthly)
else 
dateadd(day,@gap, dateadd(month, datediff(month,0,dateadd(month,1,Bimonthly)),0))
END
,rn+1
from cte
where rn< (datediff(month,@StartYear, @endYear)+1)*2

)
select 
case WHEN datename(dw, Bimonthly)='Saturday' THEN
      dateadd(day,-1, Bimonthly) 
      WHEN datename(dw, Bimonthly)='Sunday' THEN 
      dateadd(day,-2, Bimonthly) 
     else 
      Bimonthly
     end 

     ,rn

from cte

這篇關于如何在 SQL Server 中獲得一年中每個月的雙周日期?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 亚洲一av | 九九热精品在线 | 中文字幕视频在线观看免费 | 精品福利在线视频 | 日韩不卡一区二区 | 日韩一区二区三区在线观看视频 | 亚洲黄色高清视频 | 黑人巨大精品欧美一区二区免费 | 最新日韩欧美 | 欧美一区二区三区在线 | 国产粉嫩尤物极品99综合精品 | 91精品国产一区二区三区 | 日韩在线中文字幕 | 中文字幕一区二区三 | 亚洲精品乱码久久久久久蜜桃91 | 欧美精品二区 | 中文字幕视频在线看5 | 日本一二三区电影 | 国产日韩精品在线 | 国产目拍亚洲精品99久久精品 | 欧美久久久久久久久 | 久久国产综合 | 日韩在线观看一区 | 国产成人在线视频播放 | 91精品国产色综合久久 | 亚洲高清一区二区三区 | 国产精品毛片 | 亚洲精品在| 免费黄视频网站 | 久久久久久久久久久蜜桃 | av中文字幕在线观看 | 天天弄天天操 | 草草视频在线观看 | 色综合一区 | 午夜电影网 | 一区二区三区视频在线观看 | 欧美午夜精品久久久久免费视 | 一级片视频免费 | 日韩在线免费视频 | www亚洲精品 | 国产日韩精品在线 |