clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 1811884 fiddles created (25308 in the last week).

DECLARE @str NVARCHAR(MAX) = 'Ben|10, Bob|325, Susan|7, Michael|99' SELECT N.PersonName, N.Amount, RunningTotal = SUM ( N.Amount ) OVER ( ORDER BY N.PersonName ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) FROM ( SELECT PersonName = LEFT ( TRIM ( Value ), CHARINDEX ( '|', TRIM ( Value ) ) - 1 ), Amount = CAST ( RIGHT ( TRIM ( Value ), CHARINDEX ( '|', REVERSE ( TRIM ( Value ) ) ) - 1 ) AS int ) FROM STRING_SPLIT ( @str, ',' ) ) N
PersonName Amount RunningTotal
Ben 10 10
Bob 325 335
Michael 99 434
Susan 7 441
 hidden batch(es)


DECLARE @str NVARCHAR(MAX) = 'Ben|10, Bob|325, Susan|7, Michael|99'; SELECT s.col, PersonName, Amount,rn, RunningTotal = SUM(Amount) OVER(ORDER BY rn ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM (SELECT @str) s(col) CROSS APPLY (SELECT PersonName = LEFT(TRIM(Value), CHARINDEX('|', TRIM (Value))-1) ,Amount = CAST(RIGHT(TRIM(Value), CHARINDEX('|', REVERSE (TRIM(Value)))-1) AS INT) ,value ,rn = [key] FROM OPENJSON(JSON_QUERY( REPLACE(CONCAT('["',s.col,'"]'), ', ', '","'))) ) A
col PersonName Amount rn RunningTotal
Ben|10, Bob|325, Susan|7, Michael|99 Ben 10 0 10
Ben|10, Bob|325, Susan|7, Michael|99 Bob 325 1 335
Ben|10, Bob|325, Susan|7, Michael|99 Susan 7 2 342
Ben|10, Bob|325, Susan|7, Michael|99 Michael 99 3 441
 hidden batch(es)