How to remove invisible characters in t-sql?

后端 未结 7 929
天命终不由人
天命终不由人 2021-02-02 09:07

I tried

UPDATE TABLENAME SET COLUMNNAME = REPLACE(COLUMNNAME, \'\\t\', \'\')

But I don\'t know how to write the TAB in t-sql

7条回答
  •  温柔的废话
    2021-02-02 09:24

    Checkout this function. This will remove every invalid char

    -- =============================================
    -- Author:      xenoivan
    -- Description: clean invalid chars
    -- =============================================
    CREATE FUNCTION [dbo].[fnClean] 
    (
        @in NVARCHAR(MAX)
    )
    RETURNS  NVARCHAR(MAX)
    AS
    BEGIN
        -- Declare the return variable here
        DECLARE @out NVARCHAR(MAX)
    
        -- Add the T-SQL statements to compute the return value here
        SELECT @out = REPLACE(@in,N'َ','')
        SELECT @out = REPLACE(@out,char(9),'')
        SELECT @out = REPLACE(@out,char(13),'')
        SELECT @out = REPLACE(@out,char(10),'')
        SELECT @out = REPLACE(@out,N'‬','')
        SELECT @out = REPLACE(@out,N'‬','')
        SELECT @out = REPLACE(@out,N'‬‬','')
        SELECT @out = REPLACE(@out,N'‎', '')--its a hidden character
        SELECT @out = REPLACE(@out,N'‎', '')--ltr code
        SELECT @out = REPLACE(@out,N'‎', '')--rtl code
        SELECT @out = REPLACE(@out,N'۰', '0')
        SELECT @out = REPLACE(@out,N'۱', '1')
        SELECT @out = REPLACE(@out,N'۲', '2')
        SELECT @out = REPLACE(@out,N'۳', '3')
        SELECT @out = REPLACE(@out,N'۴', '4')
        SELECT @out = REPLACE(@out,N'۵', '5')
        SELECT @out = REPLACE(@out,N'۶', '6')
        SELECT @out = REPLACE(@out,N'۷', '7')
        SELECT @out = REPLACE(@out,N'۸', '8')
        SELECT @out = REPLACE(@out,N'۹', '9')
        SELECT @out = REPLACE(@out,N'٠', '0')
        SELECT @out = REPLACE(@out,N'١', '1')
        SELECT @out = REPLACE(@out,N'٢', '2')
        SELECT @out = REPLACE(@out,N'٣', '3')
        SELECT @out = REPLACE(@out,N'٤', '4')
        SELECT @out = REPLACE(@out,N'٥', '5')
        SELECT @out = REPLACE(@out,N'٦', '6')
        SELECT @out = REPLACE(@out,N'٧', '7')
        SELECT @out = REPLACE(@out,N'٨', '8')
        SELECT @out = REPLACE(@out,N'٩', '9');
    
        -- Return the result of the function
        RETURN @out
    
    END
    

提交回复
热议问题