Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2002
    Posts
    36

    Unanswered: Replacing Values in a string

    Thanks again to everyone who has helped me so far!

    Now I'm back again with yet another question:

    Is there any way to replace mulitple values in a string? I have a field containing phone numbers, with several different separators (some dashes, some slashes) and I'd like to replace these characters with nothing so I have a single continuous number. I know how to do one at a time using replace, but can I remove all the offending characters in one shot (in a select statement)?

    For Example:

    (123) 456-7890 -> 1234567890 (removing parentheses and dash)
    987/654-3210 -> 9876543210 (removing slash and dash)

    Thanks in advance!
    Dirk

  2. #2
    Join Date
    Dec 2001
    Location
    Toronto, Canada
    Posts
    335
    You can embed the REPLACE statements
    Code:
    declare @x varchar(20)
    
    set @x = '(421) 567-0909'
    
    select @x,REPLACE(
                     REPLACE(
                        REPLACE(REPLACE(@x,'(',''),')',''),'-',''),' ','')
    
    --------------- ------------
    (421) 567-0909  4215670909
    MCDBA

  3. #3
    Join Date
    Jun 2002
    Posts
    36
    Thanks, that works for me! I thought that was the answer but I was having syntax problems with my parentheses. Guess I can't count!

    Thanks again,
    Dirk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •