我有一个表格,用于存储订单日期YYYY-MM_DD。
如何创建具有以下要求的会计年度和会计季度:会计年度:
财政季度:
我试过了
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句