I need to update table b with data from table A please advise, please the case
table A as below
|ID | balance|
-----------------------
|10 | 360 |
-----------------------
|20 | 300 |
-----------------------
table B as below
----------------------------------------------------------
|ID | count | value | settlementvalue | mode |
----------------------------------------------------------
10 1 100 100
10 2 100 100
10 3 100 null
10 4 100 null
10 5 100 null
10 6 100 null
10 7 100 null
10 8 100 null
10 9 100 null
10 10 100 null
20 1 100 100
20 2 100 null
20 3 100 null
20 4 100 null
20 5 100 null
20 6 100 null
20 7 100 null
20 8 100 null
20 9 100 null
20 10 100 null
i need to read the balance from table A and update the first null value in settlement value in table B with value in column value and then decrease the balance then we go to update the next row until the balance become less than the value we will put it in mod column
the final result should be as below: table B as below
ID count value settlementvalue mode
10 1 100 100
10 2 100 100
10 3 100 100
10 4 100 100
10 5 100 100
10 6 100 null 60
10 7 100 null
10 8 100 null
10 9 100 null
10 10 100 null
20 1 100 100
20 2 100 100
20 3 100 100
20 4 100 100
20 5 100 null
20 6 100 null
20 7 100 null
20 8 100 null