Hi All,
I am using SQL Server 2008 R2. I am using SSRS. I am creating a chart.
I need to write query for the sum of rolling value for the year and month selected.
I have 3 parameters i.e. LocationId ,Year and Month
When i select the year as 2012 and Month as 11,
i need to get values from DEC 2011 to NOV 2012.
my requirement is,
dec 2011 = (sum(A.column) of Jan 2011 to Dec 2011)
jan 2012 = (sum(A.column) of feb 2011 to jan 2012)
feb 2012 = (sum(A.column) of mar 2011 to feb 2012)
mar 2012 = (sum(A.column) of Apr 2011 to Mar 2012)
Apr 2012 = (sum(A.column) of May 2011 to Apr 2012)
May 2012 = (sum(A.column) of Jun 2011 to May 2012)
Jun 2012 = (sum(A.column) of Jul 2011 to Jun 2012)
Jul 2012 = (sum(A.column) of Aug 2011 to Jul 2012)
Aug 2012 = (sum(A.column) of Sep 2011 to Aug 2012)
Sep 2012 = (sum(A.column) of Oct 2011 to Sep 2012)
Oct 2012 = (sum(A.column) of Nov 2011 to Oct 2012)
Nov 2012 = (sum(A.column) of Dec 2011 to Nov 2012)
I have used union all for the query and have written it seperately.
I need to write it so that it works for all years and months which is selected.
when i select 10 2012 in the parameters, i need to get values from Nov 2011 to Oct 2012.where Nov 2011 = (Sum of Dec 2010 to Nov 2011) and so on.
Please help me out.. Any help is highly appreciated.
Thanks in advance, Akhila Vasishta