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 |
lloyddobler
Starting Member
4 Posts |
Posted - 2008-04-08 : 11:09:06
|
I need to create a query that helps satisfy this: I need to calculate a monthly savings...easy enough, just divide annual savings by 12. But I need to calculate the annual savings based on the month the project was implemented (DATE field). so, my annual savings for P#1 would be 12,000, whereas my annual savings for P#2 would only be 10,000. The leftover 2,000 would carry forward to 2008. That brings in my second part. I need to be able to calculate a rolling 12 month YTD savings (realized). So, need to add all P# est monthly savings for past 12 months. Table (I've used 12,000 for all projects to make things simpler for calculating) P# DATE annual SAVINGS1 01/01/07 12,0002 03/03/07 12,0003 07/07/07 12,0004 10/10/07 12,0005 02/02/08 12,0006 03/03/08 12,000Example: 2007 est annual savings would be 12,000 (P#1) + 10,000 (P#2) + 6,000(P#3) + 3,000(P#4)= 28,0002008 est annual savings would be 2,000 (P#2 carry over) + 6,000 (P#3 carry over) + 9,000 (P#4 carry over) + 11,000 (P#5) + 10,000 (P#6) = 38,000YTD realized savings would be 9,000 (P#3->6 months of 07 + 3 months of 08) + 6,000 (P#4) + 2,000 (P#5) + 1,000 (P#6) = 18,000Now...I haven't a clue where to begin to write this! I hope it makes sense! Would love some guidance or a point in the right direction. please and thanks.Hey my brother, can I borrow a copy of your "Hey Soul Classics"? No, my brother, you have to go buy your own. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-08 : 11:16:41
|
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|
|