Search code examples
sqlsql-servert-sqlrecordtrim

Removing trailing spaces and whitespaces from SQL Server column


I have a column in my SQL Server database and it has white spaces from left and right site of the record. Basically it's a nvarchar(250) column.

I have tried removing white spaces completely like this:

UPDATE MyTable 
SET whitespacecolumn = LTRIM(RTRIM(whitespacecolumn)) 

But this didn't work out at all, the whitespace is still there. What am I doing wrong here?


Solution

  • Check the below;

    1. Find any special characters like char(10), char(13) etc in the field value.
    2. Check the status of ANSI_PADDING ON. Refer this MSDN article.