Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove invisible characters in t-sql?

Tags:

tsql

I tried

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

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

like image 207
Jader Dias Avatar asked Aug 07 '09 16:08

Jader Dias


People also ask

How do I remove an invisible character in SQL?

Declare @nl Char(2) = char(13) + char(10) Declare @tab Char(1) = char(9) etc... Then you can use those declared variables anywhere in the rest of the proc without loss of clarity...

How do I remove all characters from a string in SQL?

SQL Trim Function Another function you can use to remove characters from a string is the trim() function. The trim function will remove all leading and trailing whitespace characters from a string by default.

Which special characters are not allowed in SQL?

Names can contain (but cannot begin with) the following special characters: 0 through 9, #, @, and $.


4 Answers

The ASCII code for tab is 9; you could try

update tablename set columnname = replace(columnname, char(9), '')
like image 168
Adrien Avatar answered Oct 18 '22 03:10

Adrien


For TAB and ENTER

SELECT
    -- TRIM AND REPLACE `TAB` AND `ENTER`
    LTRIM(RTRIM(
        REPLACE(
            REPLACE(
                REPLACE(columnname, CHAR(9), ' '),
            CHAR(13), ' '),
        CHAR(10), ' ')
    ))
like image 26
Eduardo Cuomo Avatar answered Oct 18 '22 04:10

Eduardo Cuomo


In the beginning of my TSql sProcs, I often put

   Declare @nl Char(2) = char(13) + char(10)
   Declare @tab Char(1) = char(9)
   etc...

Then you can use those declared variables anywhere in the rest of the proc without loss of clarity...

like image 14
Charles Bretana Avatar answered Oct 18 '22 05:10

Charles Bretana


You can put a tab character in the string, just press the tab key.

That will work, but it's not very readable.

like image 4
Guffa Avatar answered Oct 18 '22 05:10

Guffa