views:

31

answers:

2

I have a MySQL InnoDB database.

I have a 'phone_number' field.

My data is dirtly in the sense that sometimes my data is:

(111) 222-3333
111-222-3333
111.222.3333
(111) 222 3333

How can I strip all spaces and parenthesis from my 'phone_number' field to only store my phone_number in the following format '1112223333'?

What would the SQL be to UPDATE my 'phone_number' field to have all data in the format '1112223333'?

For example, pseudo code:

UPDATE phone_number = STRIP_SPACES_AND_PARATENSIS(phone_number) FROM homes;
A: 

See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=103752 .

Borealid
That appears to be using SQL Server specific functions. No?
TeddyR
Yes, it is - but the stored-procedure logic is the same as what you'd use in MySQL. I don't think MySQL has a magic function for this. Perhaps a SQL guru will correct me :-).
Borealid
A: 
update homes set phone_number=replace(replace(replace(replace(replace(phone_number,'-',''),'(',''),')',''),'.', ''), ' ', '');
ggiroux