• Carl,

    Two suggestions:

    1. Define @SomeText AS VARCHAR(8000) instead of VARCHAR(MAX)

    2. Use the LATIN1_GENERAL_BIN collation - and only on @SomeText, not the replace chars.

    VARCHAR(MAX) variables require a tempdb worktable, whereas VARCHAR(8000) does not.

    A binary collation is even faster than a SQL collation, and safe to use with your replacement characters, since you are using code point values.

    Paul