?
Solved

Remove - from phone number

Posted on 2001-07-16
3
Medium Priority
?
223 Views
Last Modified: 2006-11-17
How can I write and update query to remove the dashes from my table.  I have 2 phone number fields that look like this 555-555-5555 I want to remove the dashes.

Thanks
0
Comment
Question by:cat4larry
  • 2
3 Comments
 
LVL 3

Expert Comment

by:trouta
ID: 6287504
update person set phone_number = replace(phone_number, '-', '')

if you are running SQL 7.0 or 2000
0
 

Author Comment

by:cat4larry
ID: 6287559
Trouta thanks you answered the question one last thing what if the phone number is formated like this (555)-555-5555 how can i remove the () and -'s  thanks very much
0
 
LVL 3

Accepted Solution

by:
trouta earned 100 total points
ID: 6287565
either

update person set phone_number = replace(phone_number, '-', '')
update person set phone_number = replace(phone_number, ')', '')
update person set phone_number = replace(phone_number, '(', '')

or

update person set phone_number = replace(replace(replace(phone_number, '-', ''), ')', ''), '(', '')




0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question