繁体   English   中英

财政年度和财政季度

[英]Fiscal year and fiscal quarter

我有一张表,用于存储订单日期 YYYY-MM_DD。

如何创建具有以下要求的会计年度和会计季度: 会计年度:

  1. Fiscal_Year_2000 的开始日期是 1999-07-01,结束于 2000-06-31
  2. Fiscal_year_2001 的开始日期是 2000-07-01,结束日期是 2001-06-31

财政季度:

  1. Fiscal_Quarter_1 例如 FY2000 从 1999-07-01 开始到 1999-09-31 结束
  2. 2000 财年 FQ2、FQ3、FQ4
  3. 2001 财年 FQ1/2/3/4

我试过

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]

我得到了一些非常奇怪的结果。 任何帮助都受到高度赞赏。

输出应该是这样的:

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

只需添加六个月并使用年份。 例如,如果您想要 2000 财年:

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

如果您想要 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