久久久久久久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)
主站蜘蛛池模板: 亚洲午夜在线 | 夜夜操夜夜操 | 国产精品久久久一区二区三区 | 国产1级片 | 国产精品av一区二区 | 91久久久久久久久 | 91精品久久久久 | 福利视频网站 | 日韩av不卡在线观看 | 91av精品| 欧美成人精品欧美一级乱黄 | 免费成人毛片 | 日日夜夜精品 | 91久久久久国产一区二区 | 成人一区二区在线 | 国产成人区 | 中文天堂av | 亚洲在线免费观看 | 午夜免费观看视频 | 国产毛片一级 | 国产三级午夜理伦三级 | 乳色吐息樱花 | 欧美黄色三级视频 | 伊人黄色 | 91视频观看 | 午夜影院在线观看视频 | 午夜久久久久久 | 2018天天操 | 亚洲激情综合网 | 亚欧洲精品在线视频免费观看 | 天天干天天操天天摸 | av不卡一区 | 国产精品成人国产乱一区 | 免费视频一区二区 | 午夜免费剧场 | 精品一区二区三 | 三级黄色片 | 亚洲伊人av | 日韩精品在线免费观看 | 在线观看免费黄色 | 久久久久亚洲精品 |