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 |
|
sentiboy
Starting Member
3 Posts |
Posted - 2005-09-06 : 13:18:12
|
| Hi,I have to generate a report in which I need netqty as a field which should be equal to sum of "item qty" field in this and all previous rows.e.g.I am having following tableTableName: itemmasteritemid itemname qty 1. Item1 22. Item2 43. Item3 5I need new table from sql as :itemid itemname qty netqty1. Item1 2 22. Item2 4 63. Item3 5 11ThanksBhavuk |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-09-06 : 13:23:29
|
| How are you presenting or creating this report? It is much easier and more efficent to calculate running totals on the report itself, almost all reporting tools these days support those quite easily. |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2005-09-07 : 04:52:08
|
| SELECT ItemID, Itemname, Qty, (SELECT SUM(Qty) FROM table WHERE ItemID <= a.ItemID) AS NetQtyFROM table aORDER BY ItemIDI think this will work...--Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-08 : 01:32:49
|
| It should be noted that using query to generate running total there will be performance issue if the table has millions of records. It is better to use Running Total option of ReportBhavuk, which reporting tool are you using?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|