I have trailing spaces in a column in a SQL Server table called Company Name
.
All data in this column has trailing spaces.
I want to remove all
To remove Enter:
Update [table_name] set
[column_name]=Replace(REPLACE([column_name],CHAR(13),''),CHAR(10),'')
To remove Tab:
Update [table_name] set
[column_name]=REPLACE([column_name],CHAR(9),'')
update MyTable set CompanyName = rtrim(CompanyName)
SQL Server does not support for Trim() function.
But you can use LTRIM() to remove leading spaces and RTRIM() to remove trailing spaces.
can use it as LTRIM(RTRIM(ColumnName)) to remove both.
update tablename
set ColumnName= LTRIM(RTRIM(ColumnName))
I had the same problem after extracting data from excel file using ETL and finaly i found solution there :
https://www.codeproject.com/Tips/330787/LTRIM-RTRIM-doesn-t-always-work
hope it helps ;)
To just trim trailing spaces you should use
UPDATE
TableName
SET
ColumnName = RTRIM(ColumnName)
However, if you want to trim all leading and trailing spaces then use this
UPDATE
TableName
SET
ColumnName = LTRIM(RTRIM(ColumnName))
Use the TRIM SQL function.
If you are using SQL Server try :
SELECT LTRIM(RTRIM(YourColumn)) FROM YourTable