Solved

SQL Fiscal Year Starting 7/1 - Ending 6/30

Posted on 2014-12-18
4
155 Views
Last Modified: 2015-09-22
Could you please help me create formulas for these -in SQL 2012:

FY Starting 7/1 - Ending 6/30

1) FY End Date of GETDATE()
2) FY End Date of Last year
3) FY Start Date - 10 years ago

Each of these should be in format m/d/yyyy - 7/1/2014

Thanks so much!
Scott
0
Comment
Question by:Scott Williams
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 55

Expert Comment

by:Huseyin KAHRAMAN
ID: 40507566
here

\
select 
CAST(cast(datepart(year,getdate()) as varchar)+'0630'  AS date) fye_this,
CAST(cast(datepart(year,getdate())-1 as varchar)+'0630'  AS date) fye_last,
CAST(cast(datepart(year,getdate())-10 as varchar)+'0701'  AS date) fys_past10year

fye_this	fye_last	fys_past10year
2014-06-30	2013-06-30	2004-07-01

Open in new window

0
 
LVL 55

Accepted Solution

by:
Huseyin KAHRAMAN earned 500 total points
ID: 40507570
and you can use convert(varchar,getdate(),101) to convert to mm/dd/yyyy

select 
convert(varchar,CAST(cast(datepart(year,getdate()) as varchar)+'0630'  AS date),101) fye_this,
convert(varchar,CAST(cast(datepart(year,getdate())-1 as varchar)+'0630'  AS date),101) fye_last,
convert(varchar,CAST(cast(datepart(year,getdate())-10 as varchar)+'0701'  AS date),101) fys_past10year

fye_this	fye_last	fys_past10year
06/30/2014	06/30/2013	07/01/2004

Open in new window

0
 

Author Closing Comment

by:Scott Williams
ID: 40507644
Thanks a lot!!!
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40988979
Scott - I just kicked out an article that deals specifically with Fiscal calendar planning --> SQL Server Calendar Table:  Fiscal Years.   Let me know if this helps you, and if yes please click on the 'Good Article' button and provide some feedback.  Thanks.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question