How would you calculate the fiscal year from a date field in a view in SQL Server?
相关问题
- sql execution latency when assign to a variable
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
- SQL to Parse a Key-Value String
相关文章
- Entity Framework 4.3.1 failing to create (/open) a
- Code for inserting data into SQL Server database u
- Delete Every Alternate Row in SQL
- Linux based PHP install connecting to MsSQL Server
- SQL Azure Reset autoincrement
- How do we alias a Sql Server instance name used in
- Is recursion good in SQL Server?
- How can I convert a OLE Automation Date value to a
More simple for Australians :)
(YEAR(DATEADD(Month,-((DATEPART(Month,[Date])+5) %12),[Date]))+) AS Financial_Year
I don't think you can, because there is no universal fiscal calendar. Fiscal years vary between businesses and countries.
ADDENDUM: What you would need to do is have a separate DB table consisting of a fiscal start date, and a fiscal end date for each applicable year. Use the data in that table to calculate the fiscal year given a particular date.
Here's my version which returns fiscal year as FYyyyy - fiscal year begins 7/1
i.e. 6/1/2015 -> FY1415, 7/1/2015 -> FY1516
String functions could be better...
Start of fiscal year:
End of Fiscal Year:
Replace
getdate()
with your own date if requiredI've extended the answer posted by ChrisF and Conficker.