75

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.

halfer
  • 19,471
  • 17
  • 87
  • 173
happysmile
  • 7,179
  • 36
  • 101
  • 181
  • You could create a Sql function as described here https://stackoverflow.com/questions/14211346/how-to-remove-white-space-characters-from-a-string-in-sql-server – DMK Sep 18 '17 at 14:26

5 Answers5

165

Try this code

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

char(9) is the TAB character

KaR
  • 1,751
  • 1
  • 11
  • 3
17
UPDATE Table SET Column = REPLACE(Column, char(9), '')
Andrei Karcheuski
  • 2,866
  • 3
  • 36
  • 38
10

Use the Below Code for that

UPDATE Table1 SET Column1 = LTRIM(RTRIM(REPLACE(REPLACE(REPLACE(Column1, CHAR(9), ''), CHAR(10), ''), CHAR(13), '')))`
Sumant Singh
  • 730
  • 1
  • 10
  • 15
0

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
bouvierr
  • 3,399
  • 3
  • 26
  • 28
-3

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

Subroto Biswas
  • 485
  • 5
  • 5