Need t-sql help in generating running total. Here is sample data:

```
WITH SRC AS (
SELECT 0 AS A, 8.0 AS B,1 AS C UNION ALL
SELECT 1, 3.0,2 UNION ALL
SELECT 2, 7.0,3 UNION ALL
SELECT 3,1.0,4 UNION ALL
SELECT 4, 5.0,5 UNION ALL
SELECT 5, 6.0,6 UNION ALL
SELECT 6, 4.0,1 UNION ALL
SELECT 7, 3.0,2 UNION ALL
SELECT 8, 9.0,3 UNION ALL
SELECT 9, NULL,4 UNION ALL
SELECT 10, NULL,5 UNION ALL
SELECT 11, 5.0,1 UNION ALL
SELECT 12, 2.0,2 UNION ALL
SELECT 13, 8.0,3 UNION ALL
SELECT 14, NULL,4)

```

Using the above data i'm generating below columns including Running Total

```
 SELECT *
,(SUM(MAIN.B) OVER(PARTITION BY MAIN.E ORDER BY mAIN.a))Running_Total

FROM (
        SELECT * ,

        (case when c=1 then 1 else 0 end) as D ,

        (sum(case when C=1 then c end) over(order by A)) E FROM src
        )MAIN

```

Here is the Logic for Column D & E

```
Col D: is Generated based on Col:C if its 1 then 1 else its 0
Col E: is Sum of rows where Col: C is 1

```

The column Running Total is generated using sum for column: B using partitioning of Col: E.
Now i need another column: New\_Total which is a kind of running total based on Col: B. Requirement if the total exceeds 10 then retain the current row value. Here is the output i need

[![enter image description here](https://i.stack.imgur.com/odD8d.png)](https://i.stack.imgur.com/odD8d.png)

Please help in generating the result