SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru htown's Avatar
    Join Date
    Mar 2005
    Posts
    674
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with another SQL query

    I have a few telephone numbers for each record in a table. I want to search all fields within a table for telephone numbers in the format of:
    (123) 555-5555 and change it to 123-555-5555

    How would I go about doing that?

    Many thanks,
    Houston
    Houston Brown
    Split Light Designs
    Bringing your ideas to light.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    assuming there's nothing before or after the phone number...

    also assuming mysql, because, well, because you didn't specify your database system...
    Code:
    UPDATE daTable
       SET daColumn = CONCAT( SUBSTRING(daColumn FROM 2 FOR 3) -- 213
                            , '-'
                            , SUBSTRING(daColumn FROM 7 FOR 9) -- 555-5555
                            )
     WHERE daColumn LIKE '(___)____-____'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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