Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change format of values in a column 2

Status
Not open for further replies.

timeiu2009

Technical User
Mar 2, 2009
17
US
I'm hoping this will be an easy question for someone who isn't a total SQL noob like myself. I have a table with a column named PHONE_NUMBER, which has thousands of phone numbers all formatted like "123.456.7890". Turns out for the application to work, the phone numbers have to be formatted with dashes like "123-456-7890". What is the best way to change the "."'s to "-"'s?
 
Use the REPLACE command. Make the SQL Server BOL (Books Online) your friend.

Anyways the command is simple:
Code:
SELECT REPLACE(PHONE_NUMBER, '.', '-')

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
If you want to change the field to the new format, like Bill suggested you would do...

update yourtablenamehere
set PHONE_NUMBER=REPLACE(PHONE_NUMBER, '.', '-')

Simi

 
That did it! Thanks to both of you for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top