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

在 T-SQL 中創建會計日歷

Create a fiscal calendar in T-SQL(在 T-SQL 中創建會計日歷)
本文介紹了在 T-SQL 中創建會計日歷的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試創建一個會計日歷,其中會計年度從 7 月 1 日開始,一周被定義為周一至周日.

I am trying to create a fiscal calendar in which the fiscal year starts July 1 and a week is defined as Monday to Sunday.

但是例如;如果一個月中一周的第一天是星期六,那么星期六到星期日將被視為該月的第 1 周,新的一周從星期一開始,到星期日結束,依此類推.

But for example; if the 1st day in a week in a month is a Saturday, then Saturday to Sunday will be seen as 1 week in that month and the new week starts on Monday and ends on Sunday and so on.

請參閱下面我要創建的表格示例:

See sample of the table I want to create below:

  • 期間是指會計年度的月份.
  • Week 是該月的周數.
  • 開始日期(周開始日期)是一周開始的那一天
  • 結束日期(周結束日期)是一周結束的那一天.
  • 星期幾是開始日期和結束日期之間的日期.
  • 年份

我想我需要一個程序,它可能需要會計年度的第一天,然后遍歷一年中的所有日子,添加列開始和結束日期、周數、期間和日期所屬的年份.

I am thinking that I need a procedure that maybe takes the first day of the fiscal year then iterates through all the days of the year adding the columns start and end date, week number, period and year the day belongs to.

推薦答案

另一種選擇.這將生成 50 年是 0.703 秒

Yet another option. This will generate 50 years is 0.703 seconds

示例

Set DateFirst  1

Declare @Date1 date = '2017-07-01'
Declare @Date2 date = '2019-06-30'


Select Period    = Dense_Rank() over (Partition By FY Order By FM)
      ,Week      = Dense_Rank() over (Partition By FY,FM Order By FW)
      ,StartDate = Min(D) over (Partition By FY,FM,FW )
      ,EndDate   = Max(D) over (Partition By FY,FM,FW )
      ,DayOfWeek = D
      ,Year      = FY
 From (
        Select FY = DatePart(Year,@Date1)-1+sum(case when convert(varchar(5),@Date1,101)=convert(varchar(5),D,101) then 1 else 0 end) over (Order By D)
              ,FM = sum(case when DatePart(Day,D)=DatePart(Day,@Date1) then 1 else 0 end) over (Order By D)
              ,FW = sum(case when DatePart(WeekDay,D)=1 then 1 else 0 end) over (Order By D)
              ,D
         From (
                Select Top (DateDiff(DAY,@Date1,@Date2)+1) 
                       D  = DateAdd(DAY,-1+Row_Number() Over (Order By (Select Null)),@Date1) 
                 From  master..spt_values n1,master..spt_values n2
              ) A1
      ) A
 Order By D

這篇關于在 T-SQL 中創建會計日歷的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 成人av鲁丝片一区二区小说 | 视频一区二区三区中文字幕 | 成人性视频在线播放 | 一级女毛片 | 欧美久久一区 | 在线看91 | 久久免费看 | 午夜视频在线播放 | 天天插天天狠天天透 | 一区精品视频 | 成人精品毛片国产亚洲av十九禁 | 婷婷去俺也去 | 狠狠躁躁夜夜躁波多野结依 | 91亚洲一区| 欧美在线视频观看 | 欧美二三区 | 亚洲在线 | 网址黄 | 久久久久国色av免费观看性色 | 国产91久久久久蜜臀青青天草二 | 成人免费视频网站在线观看 | 久久亚洲欧美日韩精品专区 | 狠狠爱视频| 成人一区在线观看 | 中文字幕一区二区三区日韩精品 | 久久久久久久一级 | 久久精品久久综合 | 国产三级在线观看播放 | 精品国产免费人成在线观看 | 网黄在线| 日本在线视频一区二区 | 国产成人精品一区二区 | 精品国产乱码一区二区三区 | 中文精品一区二区 | 天天插天天射天天干 | 日韩二 | 亚洲视频一区二区三区 | 欧美精品91爱爱 | 亚洲一区中文字幕 | 亚洲国产精品一区二区久久 | 中文字幕亚洲欧美日韩在线不卡 |