• I too think nested REPLACEs would probably be fastest.

    You could do a simple function, but I'm not sure that would perform as well, let alone better ... but, really, with SQL, it's hard to tell so you may want to give it a try :-).

    CREATE FUNCTION dbo.RemoveSpecifiedCharsFromString (

    @string varchar(2000),

    @charsToRemove varchar(50)

    )

    RETURNS varchar(2000)

    AS

    BEGIN

    WHILE PATINDEX('%[' + @charsToRemove + ']%', @string) > 0

    SET @string = STUFF(@string, PATINDEX('%[' + @charsToRemove + ']%', @string), 1, '')

    RETURN @string

    END --FUNCTION

    DECLARE @string varchar(2000)

    DECLARE @charsToRemove varchar(50)

    SET @charsToRemove = CHAR(00) + CHAR(01) + CHAR(02) + CHAR(03) + CHAR(04) + CHAR(05) + /*... + */

    CHAR(09) + CHAR(10) + /* ... + */ CHAR(13) + /* ... + */ CHAR(31)

    SELECT string, dbo.RemoveSpecifiedCharsFromString(string, @charsToRemove)

    FROM (

    SELECT 'abc' + CHAR(10) + CHAR(13) + CHAR(01) + 'def' AS string UNION ALL

    SELECT 'ghi' + CHAR(03) + CHAR(04) + REPLICATE(CHAR(05), 10) + 'jkl'

    ) AS test_data

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.