locked
get rid of special character RRS feed

  • Question

  • Hi i have data like this in one column

    BEARINGS\\\
    BEARINGS\BEARING LOCK NUTS\\
    BEARINGS\BEARING LOCK WASHERS\\
    BEARINGS\MISCELLANEOUS BEARINGS\\

    I want to get rid of the '\' at the end of the string

    Please help me.

    Friday, September 9, 2011 2:54 PM

Answers

  • See my answer in your other thread:

     

    declare @t table (Info1 varchar(100))
    insert into @t values ('BEARINGS\\\'),
    ('BEARINGS\BEARING LOCK NUTS\\'),
    ('BEARINGS\BEARING LOCK WASHERS\\'),('BEARINGS\MISCELLANEOUS BEARINGS\\'),('Test')
    
    select case when RIGHT(Info1,1) = '\' then SUBSTRING(Info1, 1, 
    LEN(Info1) + 1 -PATINDEX('%[^\]%',reverse(Info1))) ELSE Info1 END as Cleaned, Info1 from @t 

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    • Edited by Naomi N Friday, September 9, 2011 3:04 PM
    • Marked as answer by Daniel256 Friday, September 9, 2011 3:09 PM
    Friday, September 9, 2011 3:03 PM