[英]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:如何创建具有以下要求的会计年度和会计季度: 会计年度:
Fiscal Quarters:财政季度:
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.