• Carlo Romagnano (1/10/2013)


    Your script replace 5 consecutive digits with 2 stars.

    Here an optimized version.

    declare @substr varchar(50)--substring of input string in while loop

    declare @index int--index of number in the substring

    set @substr = '1234567890abc89900123456abcde'

    while 1=1

    begin

    select @index = PATINDEX('%[0-9][0-9][0-9][0-9][0-9]%',@substr)

    if(@index < 1)

    break

    SELECT @substr = STUFF ( @substr, @index, 5 ,'**' )

    end

    print @substr

    Thanks for the update.