Remove Trailing Spaces and Update in Columns in SQL Server

AGM Raja picture AGM Raja · Feb 8, 2013 · Viewed 375.1k times · Source

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 those, and I want to have the data without any trailing spaces.

The company name is like "Amit Tech Corp "

I want the company name to be "Amit Tech Corp"

Answer

rs. picture rs. · Feb 8, 2013

Try SELECT LTRIM(RTRIM('Amit Tech Corp '))

LTRIM - removes any leading spaces from left side of string

RTRIM - removes any spaces from right

Ex:

update table set CompanyName = LTRIM(RTRIM(CompanyName))