Trim spaces in string - LTRIM RTRIM not working

后端 未结 8 1792
你的背包
你的背包 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 19:54

    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", '')));
    

提交回复
热议问题