Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
kond.mohan
Posting Yak Master
213 Posts |
Posted - 2013-06-27 : 11:00:42
|
hi alli have created cte for calculating cumulative budget in ssms 2008 but i got the out put below manner131 2013-01 13 7.036400 13131 2013-02 13 6.758130 26131 2013-03 13 16.188320 39131 2013-04 13 18.601500 52131 2013-05 13 7.685010 65131 2013-06 13 10.079660 78175 2013-01 13 10.142280 91175 2013-02 13 23.531130 104with cteas( select #temp4.MONTHYEAR,#temp4.AVGBUDGET,#temp3.ACHIVEMENTASONDATE/100000 ACHIVEMENTASONDATE, LEFT(((#temp3.ACHIVEMENTASONDATE/100000)/nullif(#temp4.AVGBUDGET,0)*100),5) "%OFACHIVEMENT", #temp3.EMP_NO from #temp3 inner join #temp4 on #temp3.EMP_NO=#temp4.EXECUTIVE and #temp3.INVOICEDATE=#temp4.MONTHYEAR ---where #temp3.EMP_NO in (725,719)-- where #temp4.MONTHYEAR between '2013-01' and '2013-04' group by #temp4.monthyeAR,#temp4.AVGBUDGET,#temp3.ACHIVEMENTASONDATE,#temp3.EMP_NO,#temp4.EXECUTIVE ) select emp_no, monthyear,avgbudget,ACHIVEMENTASONDATE,sum(avgbudget) over (order by emp_no,monthyear) as cum from cte order by emp_nobut i need to get the cumulative based on employee wiseif anyone knows explain me the logic |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-27 : 11:03:56
|
[code]with cteas( select #temp4.MONTHYEAR,#temp4.AVGBUDGET,#temp3.ACHIVEMENTASONDATE/100000 ACHIVEMENTASONDATE,LEFT(((#temp3.ACHIVEMENTASONDATE/100000)/nullif(#temp4.AVGBUDGET,0)*100),5) "%OFACHIVEMENT",#temp3.EMP_NO from #temp3 inner join #temp4 on #temp3.EMP_NO=#temp4.EXECUTIVEand #temp3.INVOICEDATE=#temp4.MONTHYEAR ---where #temp3.EMP_NO in (725,719)-- where #temp4.MONTHYEAR between '2013-01' and '2013-04'group by #temp4.monthyeAR,#temp4.AVGBUDGET,#temp3.ACHIVEMENTASONDATE,#temp3.EMP_NO,#temp4.EXECUTIVE)select emp_no, monthyear,avgbudget,ACHIVEMENTASONDATE,sum(avgbudget) over (partition by emp_no order by monthyear) as cum from cte order by emp_no[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|