SQL Server TRIM character

前端 未结 17 2160
感情败类
感情败类 2020-12-09 17:11

I have the following string: \'BOB*\', how do I trim the * so it shows up as \'BOB\'

I tried the RTRIM(\'BOB*\',\'*\') but does not work as says needs only 1 paramet

17条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 17:25

    @teejay solution is great. But the code below can be more understandable:

    declare @X nvarchar(max)='BOB *'
    
    set @X=replace(@X,' ','^')
    
    set @X=replace(@X,'*',' ')
    
    set @X= ltrim(rtrim(@X))
    
    set @X=replace(@X,'^',' ')
    

提交回复
热议问题