SQL Server TRIM character

前端 未结 17 2231
感情败类
感情败类 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条回答
  •  旧时难觅i
    2020-12-09 17:36

    How about.. (in this case to trim off trailing comma or period)

    For a variable:

    -- Trim commas and full stops from end of City
    WHILE RIGHT(@CITY, 1) IN (',', '.'))    
        SET @CITY = LEFT(@CITY, LEN(@CITY)-1)  
    

    For table values:

    -- Trim commas and full stops from end of City
    WHILE EXISTS (SELECT 1 FROM [sap_out_address] WHERE RIGHT([CITY], 1) IN (',', '.'))     
        UPDATE [sap_out_address]    
        SET [CITY] = LEFT([CITY], LEN([CITY])-1)  
        WHERE RIGHT([CITY], 1) IN (',', '.') 
    

提交回复
热议问题