How to trim a string in SQL Server before 2017?

Eric Labashosky picture Eric Labashosky · Oct 7, 2008 · Viewed 323.5k times · Source

In SQL Server 2017, you can use this syntax, but not in earlier versions:

SELECT Name = TRIM(Name) FROM dbo.Customer;

Answer

Ben Hoffstein picture Ben Hoffstein · Oct 7, 2008
SELECT LTRIM(RTRIM(Names)) AS Names FROM Customer