Replace two values

  • Hi

    I want to remove multiple characters (that are not necessary sequential) in a string.

    To remove the character 'a' from a string I use the following:

    REPLACE(mystring, 'a', '')

    But if I want to remove all 'a's 'b's and 'c's how do I do it?

    The following does not work but displays the logic I need:

    REPLACE(mystring, 'a' | 'b' | 'c', '')

    any ideas

  • You will have to use a nested REPLACE for this like the below example

    DECLARE@strVariable VARCHAR(100)

    SET@strVariable = 'a1b2c3'

    SELECTREPLACE( REPLACE( REPLACE( @strVariable, 'a', '' ), 'b', '' ), 'c', '' )


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply