hi, i have a following code:create table test_RV(id int identity(1,1),date smalldatetime,value int,running_value int,person_ID int)insert into test_RVselect '2006-02-06 00:00:00',5,3,124 union allselect '2006-03-12 00:00:00',5,1,124 union allselect '2006-03-23 00:00:00',5,4,124 union allselect '2006-02-11 00:00:00',2,2,125 union allselect '2006-03-12 00:00:00',3,1,127 union allselect '2006-03-21 00:00:00',3,3,127 union allselect '2006-02-18 00:00:00',5,5,210
what i want to achieve is for each value, to subtract the current running_valueuntil it's equal or lower than zero. for this state i want to print: date, person_IDand difference on that day.e.g. for person_ID = 124id | value | running_value | date------------------------------------------1 5 3 2006-02-062 5 1 2006-03-133 5 4 2006-03-23id1: value - running_value (5-3) = 2 (equals to zero or lower than zero not reached)id2: (new)value - running_value (2-1) = 1 (equals to zero or lower than zero not reached)id3: (new)value - running_value (1-4) = -3 (condition satisfied; print: date: 2006-03-23; person_ID:124; difference: -3) thank you.