• the only thing i'd like to mention is regarding the convert in the where clause. if you don't specify the length when you convert the current search column to varchar it, by default, will truncate the column value to a length of 30. it will also trim trailing spaces, so it would really only search the first 30 characters of the current column. see my example below:

    DECLARE @Value varchar(100)='12345678901234567890123456789012345678901234567890'

    SELECT @Value, LEN(@Value), LEN(CAST(@Value AS varchar)), LEN(CONVERT(varchar, @Value)), LEN(CAST(@Value AS varchar(1000))), LEN(CONVERT(varchar(1000), @Value))

    SET @Value=REPLACE(@Value, '0',' ')

    SELECT @Value, LEN(@Value), LEN(CAST(@Value AS varchar)), LEN(CONVERT(varchar, @Value)), LEN(CAST(@Value AS varchar(1000))), LEN(CONVERT(varchar(1000), @Value))