1

我有一张表,用于存储订单日期 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
4

1 回答 1

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
于 2020-10-22T02:30:09.550 回答