What if you do it the simple way?
;WITH cteDATA
AS(
SELECT [ReqId]=1,[Date]='20160613',HrsEarned=10,HrsBooked=-31.7,[EmpId]=100 UNION ALL
SELECT 2,'20160713', 52.7,-20,100 UNION ALL
SELECT 3,'20170613',1,-11.5,100 UNION ALL
SELECT 4,'20170713',16.7,0,100 UNION ALL
SELECT 5,'20180613',5,-16.7,100 UNION ALL
SELECT 6,'20180713',112.7,-100,100 UNION ALL
SELECT 7,'20190613',0,-0.5,100 UNION ALL
SELECT 8,'20190713',6.7,0,100
),cteAddRN
AS(
SELECT
RN = ROW_NUMBER() OVER
(
PARTITION BY C.EmpId
ORDER BY C.[Date]
)
,C.ReqId
,C.[Date]
,C.HrsEarned
,C.HrsBooked
,C.EmpId
FROM
cteDATA C
)
SELECT
EmpID, Date,
SUM(HrsEarned-HrsBooked) totals
from cteDATA
group by EmpId, Date
output:
EmpID Date totals
100 20160613 41.7
100 20160713 72.7
100 20170613 12.5
100 20170713 16.7
100 20180613 21.7
100 20180713 212.7
100 20190613 0.5
100 20190713 6.7
It think the value at the end should be 6.7, also in the method you do not have implemented yet?
After your response, I think I do miss some information (or I misinterpreted).
when you write:
100 20160713 40.7 -20.0 -1.0 --the running total here is < 0
100 20170613 1.0 -11.5 -10.5 --Expected here should be -11.5
You almost state that the '-1.0' does not count, And you claim you are missing -1.0 on the next row.
This 'missing' piece is the difference between 6.7 and 6.2. Whatever the right answer is, the definition of the problem makes it hard to guess.