会计年度和财政季度

时间:2020-10-22 02:28:42

标签: sql sql-server fiscal

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

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

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

财政季度:

  1. 例如2000财政年度的Fiscal_Quarter_1从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

1 个答案:

答案 0 :(得分:0)

只需添加六个月并使用年份即可。例如,如果您想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