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 |
|
yingchai
Starting Member
33 Posts |
Posted - 2011-06-03 : 05:56:59
|
| Hi, I need your expertise on this issue. Basically the reason to do this is to calculate YTD values.For example, I have the following data:org acc period amount--------------------------SSD ASSET 01/2011 10SSD ASSET 02/2011 15SSD ASSET 03/2011 20Based on the example above, I intend to get the following result set:org acc period amount--------------------------SSD ASSET 01/2011 10SSD ASSET 02/2011 15SSD ASSET 03/2011 20SSD ASSET YTD(01/2011) 10SSD ASSET YTD(02/2011) 25SSD ASSET YTD(03/2011) 45Any help you can provide with be greatly appreciated. |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-03 : 06:01:12
|
| select org acc period amountfrom tblunion allselect org acc period = 'YTD(' + period + ')', amount = (select sum(t2.amount) from tbl t2 where t2.period <= t.period)from tbl torder by periodBut I'm guessing that's not what you really want.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|