happysmile
happysmile

Reputation: 7777

How eliminate the tab space in the column in SQL Server 2008

I have an column with email in table customer where the data in the column contains special character: TAB

When I do a select, I need to remove the TAB space from that column.

Means there is an empty TAB space followed by the EmailID: xyz.com

I tried using the LTRIM and RTRIM but that does not work here.

Upvotes: 82

Views: 237171

Answers (5)

bouvierr
bouvierr

Reputation: 3791

Starting with SQL Server 2017 (14.x) and later, you can specify which characters to remove from both ends using TRIM.

To TRIM just TAB characters:

SELECT TRIM(CHAR(9) FROM Email)
FROM MyTable

To TRIM both TAB and SPACE characters:

SELECT TRIM(CONCAT(CHAR(9), CHAR(32)) FROM Email)
FROM MyTable

Upvotes: 3

Subroto Biswas
Subroto Biswas

Reputation: 641

See it might be worked -------

UPDATE table_name SET column_name=replace(column_name, ' ', '') //Remove white space

UPDATE table_name SET column_name=replace(column_name, '\n', '') //Remove newline

UPDATE table_name SET column_name=replace(column_name, '\t', '') //Remove all tab

Thanks Subroto

Upvotes: -4

Sumant Singh
Sumant Singh

Reputation: 1020

Use the Below Code for that

UPDATE Table1 SET Column1 = LTRIM(RTRIM(REPLACE(REPLACE(REPLACE(Column1, CHAR(9), ''), CHAR(10), ''), CHAR(13), '')))`

Upvotes: 16

Andrei Karcheuski
Andrei Karcheuski

Reputation: 3306

UPDATE Table SET Column = REPLACE(Column, char(9), '')

Upvotes: 17

KaR
KaR

Reputation: 1911

Try this code

SELECT REPLACE([Column], char(9), '') From [dbo.Table] 

char(9) is the TAB character

Upvotes: 181

Related Questions