Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to do cumulative substraction using T-Sql 2005

$
0
0

Hi ,

I want to do cumulative substraction  which will do the minus from the previous row's balance.

For example in my requirement, I have 100 orders to be completed as mentioned in below screen shot.

So, 1st Feb it will show 100 orders (since nothing completed, 100 is total no of pending orders)

On 2nd Feb,  5 orders get completed so i have to do 100-5 = 95 pending orders still

Next day, 3rd Feb, another 10 orders get completed so it should be previous balance (95) - 10 = 85

On 4th Feb, 25 orders get completed so it should be  previous balance (85) - 25 = 60

Finally, on 5th Feb,  60 orders get completed so it should be previous balance (60) - 60 = 0

Please refer to below table for the same for better understanding.

How do I do this using T-SQL 2005 (I am writing stored proc where I need to calculate this thing to find out No. of Orders Pending on each day such that finally on last day it becomes 0 means nothing pending...)

Hope it is clear. Thanks to help



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>