在sql select语句中计算财政年度? [英] calculate fiscal year in sql select statement?

查看:34
本文介绍了在sql select语句中计算财政年度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要以会计年度格式返回的日期字段.例子

I have a date field that needs to return in fiscal year format. example

Start_Date        Year 
04/01/2012 -      2013
01/01/2012 -      2012
09/15/2013 -      2014

我们需要计算

04/01/2012 to 03/31/2013 is FY 2013

04/01/2013 to 03/31/2014 is FY 2014

我们如何在 select 语句中做到这一点?

How can we do that in select statement?

推荐答案

David 有一个很好的解决方案.一个更简单的表达是:

David has a very good solution. A simpler expression is:

select year(dateadd(month, -3, start_date)) as FiscalYear

即减去3个月,然后取年份.

That is, subtract 3 months and take the year.

正如评论中所指出的,这似乎为时过早了一年.这里有两个解决方案:

As noted in the comment, this seems to produce one year too early. Here are two solutions:

select year(dateadd(month, 9, start_date)) as FiscalYear

select 1 + year(dateadd(month, -3, start_date)) as FiscalYear

这篇关于在sql select语句中计算财政年度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆