Solved

SQL 2008 R2 syntax

Posted on 2014-12-11
3
166 Views
Last Modified: 2014-12-11
How do I change phone number records in SQL table
Most of current phone numbers in the DB written in like
XXX/XXX-XXXX format  401/396-2400
I would like to change it to
 XXX-XXX-XXXX format 401-396-2400
I am looking for an exact syntax to replace all ‘/’ with ‘-‘  for SQL 2008 R2 db
0
Comment
Question by:leop1212
3 Comments
 
LVL 11

Accepted Solution

by:
John_Vidmar earned 150 total points
ID: 40495032
replace(yourfield, '/', '-')
0
 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher earned 250 total points
ID: 40495033
Easy to replace:
--UPDATE ...
--SET phone_number =
REPLACE(phone_number, '/', '-')
--WHERE phone_number LIKE '%/%'

But better would be to remove all formatting in the value stored in the db and add it back when needed when reading from the table.
0
 
LVL 51

Assisted Solution

by:HainKurt
HainKurt earned 100 total points
ID: 40495105
just get rid of all non numeric values and format when you need it...

update table set phone = replace(replace(phone,'/',''),'-','')

then, modify your app and do not allow any other character, or use 3 fields, and concat & save to db, or use some custom control that allows formatted input...

when you need it, you can always format it like:

select left(phone,3) + '-' + substring(phone, 4,3) + '-' + right(phone,4) as formatted_phone
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now