Avatar of gdemaria
gdemaria
Flag for United States of America

asked on 

SQL Server Running Balance

I think I need a cursor for this, but just wanted to check to see if any new features would make this possible.

I have a table with a date and a value, the value ends with the rest null.
I'd like to fetch the 1000 initial value and do some math on it, then save that result into the next record (1/2) and then take that value and do some math and save it to the next record and so on..

Update myTable
   set  value =  (previousTotal + column2 * aFunction( rand() ) )

Date ...   Value
1/1         1000
1/2         NULL
1/3         NULL
1/4         NULL

Cursor required?
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
Mark Wills

8/22/2022 - Mon