Trim spaces in string - LTRIM RTRIM not working

Kindly use below query it will remove space new line etc..

select LTRIM(RTRIM(REPLACE(REPLACE(REPLACE(REPLACE(Name, CHAR(10), CHAR(32)),CHAR(13), CHAR(32)),CHAR(160), CHAR(32)),CHAR(9),CHAR(32))))

You could do something brute force, such as removing the first character "manually" if it is not alphanumeric:

update table
    set name = rtrim(ltrim(case when name not like '[a-zA-Z0-9]%'
                                then stuff(name, 1, 1, '')
                                else name
                           end)
                    );

You could also search and replace that particular character:

update table
    set name = rtrim(ltrim(replace(name, "big dash", '')));

I suspect, some non readable(Non-ascii characters) inside the name column, that might not get removed as part of TRIM calls.

select convert(varbinary, Name) from table

Reading the HEX output from above query should reveal the same.

Kindly read this to find how to write functions to remove such characters.

Tags:

Sql

Sql Server