简体   繁体   English

财政年度和财政季度

[英]Fiscal year and fiscal quarter

I have a table where I store order dates YYYY-MM_DD.我有一张表,用于存储订单日期 YYYY-MM_DD。

How do I create fiscal year and fiscal quarter with the following requirements: Fiscal years:如何创建具有以下要求的会计年度和会计季度: 会计年度:

  1. start date for Fiscal_Year_2000 is 1999-07-01 and ends on 2000-06-31 Fiscal_Year_2000 的开始日期是 1999-07-01,结束于 2000-06-31
  2. start date for Fiscal_year_2001 is 2000-07-01 and end on 2001-06-31 Fiscal_year_2001 的开始日期是 2000-07-01,结束日期是 2001-06-31

Fiscal Quarters:财政季度:

  1. Fiscal_Quarter_1 for example FY2000 starts 1999-07-01 and ends 1999-09-31 Fiscal_Quarter_1 例如 FY2000 从 1999-07-01 开始到 1999-09-31 结束
  2. FQ2, FQ3, FQ4 for FY 2000 2000 财年 FQ2、FQ3、FQ4
  3. FQ1/2/3/4 for FY2001 2001 财年 FQ1/2/3/4

I tried我试过

WHERE  OrderDate BETWEEN '1999-07-01' and '2001-06-31'
DATEADD (month,7,OrderDate) AS [OrderDateNew],
DATEPART(Year, [OrderDateNew]) as [FY], 
DATEPART(QUARTER, dateadd(month,3,[OrderDateNew])) as [FQ]

I am getting some very odd results.我得到了一些非常奇怪的结果。 Any help is highly appreciated.任何帮助都受到高度赞赏。

Output should be something like:输出应该是这样的:

FY     FQ   Some other data columns of products, sales etc
2000   1
2000   2
2000   3
2000   4
2001   1
2001   2
2001   3
2001   4

Just add six months and use the year.只需添加六个月并使用年份。 For instance, if you want FY 2000:例如,如果您想要 2000 财年:

where year(dateadd(month, 6, orderdate)) = 2000

If you want the FY year and quarter, use the same idea:如果您想要 FY 年度和季度,请使用相同的想法:

select year(dateadd(month, 6, orderdate)) as fyear,
       datepart(quarter, dateadd(month, 6, orderdate)) as fquarter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM