KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Trim Spaces in Data in SQL Server
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac & Win
Published On: July 13, 2020

If connecting to an SQL Server via ODBC and it is found that there are leading/trailing spaces in your data. A quick way to remove those spaces in your data is to use the LTRIM() and RTRIM() functions in the SQL Server.

LTRIM() removes leading spaces while RTRIM() removes trailing spaces.

Given the table:


The below code is an example of using the function to remove the extra leading spaces in the table:

UPDATE Table SET Column1 = LTRIM(Column1), Coulmn2 = LTRIM(Column2);


More info on LTRIM() and RTRIM() can be found here: https://www.got-it.ai/solutions/sqlquerychat/sql-help/data-query/rtrim-ltrim-trim-functions-in-sql-server/