Cumulative duration between value resets
This is usually called a GROUPING AND WINDOWS solution.

Basically you set reset points according some rules, then you set up groups by SUMming reset points and finally use aggregated functions to get the desired value.




;WITH reset AS
(
SELECT AuditID, 
       CreditID, 
       TS, 
       Val,
       /* Next CASE returns 1 when:
             a) It is the first row of a partition
             b) Current Val=1 and previous = 0
          Otherwise it returns 0
       */
       CASE WHEN Val=1 AND COALESCE(LAG(Val) OVER (PARTITION BY CreditID ORDER BY CreditID, TS), 0) = 0
            THEN 1 ELSE 0 END AS Rst        
FROM   Taco_Val
)
  , [group] AS
    (
    SELECT AuditID, 
           CreditID, 
           TS, 
           Val,
           /* Next SUM generates a cumulative sum of reset points.
              That is a correlative number for each partition
           */ 
           SUM(Rst) OVER (PARTITION BY CreditID ORDER BY CreditID, TS) AS Grp
    FROM   reset
    )
    SELECT 
           /* Next select returns, of every group, AuditID corresponding to
              the row with the minimum TS
           */ 
           (SELECT AuditID FROM [group] WHERE CreditID = g.CreditID AND TS = MIN(g.TS)) AuditID, 
           CreditID,
           MIN(TS) as StartTS, 
           1 as Val,
           DATEDIFF(MINUTE, MIN(TS), MAX(TS)) as Duration
    FROM   [group] g
    GROUP BY CreditID, Grp;
GO



AuditID | CreditID | StartTS             | Val | Duration
:------ | :------- | :------------------ | --: | -------:
a1      | 1        | 09/08/2018 19:24:39 |   1 |      100
a9      | 1        | 09/08/2018 21:14:17 |   1 |       46
a4      | 1        | 09/08/2018 22:08:26 |   1 |        8
a3      | 1        | 09/08/2018 22:16:24 |   1 |       60
ay      | 1        | 10/08/2018 15:12:02 |   1 |        8



db&lt;>fiddle here

You'll find a brief explanation of every CTE on the previous fiddle.