Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Hot to select last month sales using fiscal calendar

$
0
0

Hi All,

I have the following query listed below

 select		DISTINCT		
							-1,
							vODS_GLBalance_test.Page,
							vODS_GLBalance_test.FiscalYearId,
							vODS_GLBalance_test.FiscalMonthOfYearId,
							GLAmount 
From ODS.Staging.vODS_GLBalance_Test
    Left Outer Join Ods.JJill.tODS_GLBalance
											ON tODS_GLBalance.FiscalYearId				= vODS_GLBalance_Test.FiscalYearId
											AND tODS_GLBalance.FiscalMonthOfYearId		= vODS_GLBalance_Test.FiscalMonthOfYearId
											AND tODS_GLBalance.Page                     = vODS_GLBalance_Test.PAGE
	  where vODS_GLBalance_Test.fiscalyearid = YEAR(GETDATE())
	  AND vODS_GLBalance_Test.fiscalMonthofyearId = MONTH(GETDATE())-1
The query runs fine and gives me the exact data if we are in lets say 2014 and months > 3.But my issue here is i am using a fiscal calendar and fiscal calendar months is not always MONTH(GETDATE())-1, for ex if we are in feb 2014 then the logic above will give us Jan 2014 but it should give me jan 2013 as the fiscal year starts from feb and ends in jan.


Can someone please help me with any suggestions?


Thanks. 


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>