Trim spaces in string - LTRIM RTRIM not working

后端 未结 8 1795
你的背包
你的背包 2021-02-03 19:14

I tried this code -

UPDATE Table
SET Name = RTRIM(LTRIM(Name))

Data type of Name is varchar(25)

None of the leading and t

相关标签:
8条回答
  • 2021-02-03 20:13

    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.

    0 讨论(0)
  • 2021-02-03 20:17

    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))))
    
    0 讨论(0)
提交回复
热议问题