• Here's a different method that might work well. Should we start testing? 😀

    DECLARE @code nvarchar(4000) = '12333345566689';

    with seed1 (a)

    as

    (

    select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all

    select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1

    ),

    numbers (n) as

    (

    select top (LEN(@code)) row_number() over (order by (select null))

    from seed1 s1, seed1 s2, seed1 s3

    )

    select a.b.value('(./text())[1]', 'nvarchar(4000)') as [text]

    from (

    select CASE WHEN SUBSTRING( @code, n, 1) = SUBSTRING( @code, n - 1, 1) THEN ''

    ELSE SUBSTRING( @code, n, 1) END

    FROM numbers

    for xml path (''), type

    )a(b)

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2