I have a task to solve well known problem in industry task to ID those CustID who have continuous activity , for given period of time and we allow little breaks between contracts.

I did first part populating matrix table like in snippet below for whole period of time and setting flag if it's active for this date, I think this is the only reliable way to do this, as contracts can have overlaps, etc..

So now I need to check if CustID is 1/0 for cont activity, I stuck into the task how to track this, let say in my example there is 3 days break which is OK, but I need to make sure that those days are one after another.

Do you have any good ideas how I can do this nicely, appreciate your help and leads. I saw some examples but they done in SAS so it's hard to understand.

```
declare @maxBreak int = 3 -- 3 days max allowed for continuse contract
declare @PeriodStart date =  '2015-1-11', @PeriodEnd date =  '2015-1-19'; 

;with matrix_dd as 
(
    select *  
    from 
        (select    111 CustID, '2015-1-11' dd, 1 Active   union  
         select    111 CustID, '2015-1-12' dd, 0 Active   union
         select    111 CustID, '2015-1-13' dd, 0 Active   union 
         select    111 CustID, '2015-1-14' dd, 0 Active   union
         select    111 CustID, '2015-1-15' dd, 1 Active   union 
         select    111 CustID, '2015-1-16' dd, 1 Active   union
         select    111 CustID, '2015-1-17' dd, 1 Active   union 
         select    111 CustID, '2015-1-18' dd, 1 Active   union
         select    111 CustID, '2015-1-19' dd, 0 Active   union 
         select    111 CustID, '2015-1-20' dd, 0 Active) a
)
select * 
from matrix_dd

```

Best
M