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

How can can i subtract the value of the column in each row ?

$
0
0

I want to subtract  the value  of the column in each row if the row is not enough then continue to next row.

For example 

ID             QTY

A               20

B               40       

C               60

I want to update this table by subtract  the value  of the column (QTY) out 70 so the result i want will be 

ID              QTY

A                20 - 70 = -50 -->  0 this row will be updated to 0 and 50 will continue to next row   

B                40 - 50  = -10 -->  0   this row will be updated to 0 and 10 will continue to next row

C                60 - 10  = 50  -->  Stop loop

How can i write the sql query for this operation , Thanks


Viewing all articles
Browse latest Browse all 12890

Trending Articles



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