By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
with t as (
select * from (values ('$D$Failov:12345:54362:28564'), ('$D$Failov:12345:')) v(failover)
),
cte as (
select failover, convert(varchar(max), NULL) as acct, convert(varchar(max), stuff(failover, 1, 10, '')) as rest, 0 as lev
from t
union all
select failover, left(rest, 5), stuff(rest, 1, 6, ''), lev + 1
from cte
where rest > ':'
)
select failover, acct, lev
from cte
where lev > 0
failover | acct | lev |
---|---|---|
$D$Failov:12345: | 12345 | 1 |
$D$Failov:12345:54362:28564 | 12345 | 1 |
$D$Failov:12345:54362:28564 | 54362 | 2 |
$D$Failov:12345:54362:28564 | 28564 | 3 |