Avatar of Ross Turner
Ross Turner
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Fiscal/Financial Year Comparison SQL

Hi EE,
I’m trying to create a stored procedure that will get the total value for the Financial Year to Date by customer, but then I want to show the previous Financial Year to Date as well for comparison.
So take today (July 9th 2012) I want to get all the values from (May  1st 2012 to July 9th 2012) for Current Financial Year .
So last year would run from (May  1st 2011 to July 9th 2011) to make an accurate comparison.

Our Financial Years always run from (May 1st to the following April 30th)

Below is a mock up picture of what i'm trying to achieve.

i seem to be going round in circles....


FY Comparison
ECLARE @CurrentFinancialYear	as Int
DECLARE @LastFinancialYear		as Int
SET		@CurrentFinancialYear	='2012'
SET		@LastFinancialYear		='2011'

Select				invoicedate												As [FullDate],
					customer.name											As [CustomerName],	
					InvoiceHead.fiscalyear									AS [FinancialYear],
					InvoiceHead.fiscalperiod								AS [FinancialYear],
					DATENAME(MONTH,InvoiceHead.invoicedate)					AS [FinancialMonthName],
					(dbo.invcdtl.sellingshipqty * dbo.invcdtl.unitprice)	AS [Value]
					
					
from				  dbo.invchead as InvoiceHead 
		INNER JOIN
                      dbo.invcdtl ON InvoiceHead.invoicenum = dbo.invcdtl.invoicenum
        INNER JOIN
                      dbo.customer ON InvoiceHead.custnum = dbo.customer.custnum
					

where	InvoiceHead.fiscalyear = @CurrentFinancialYear 
		
order by fulldate

Open in new window


Thank you for your Help....

Ross
Microsoft SQL ServerMicrosoft SQL Server 2008SQL

Avatar of undefined
Last Comment
Jim Horn

8/22/2022 - Mon
SOLUTION
Scott Pletcher

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Lowfatspread

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ross Turner

ASKER
I've stolen what i needed / got idea from both so thank you guys
Jim Horn

Ross - 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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy