Friday, January 21, 2011

MySQL fix some phone numbers

This is long and convoluted, but basically, it takes unknown inputs of phone numbers from a table:
5551212
555-1212
212555-1212
212-555-1212


and makes them all
2125551212


select Concat(if(length(PhoneNumber)< 10, "212", ""), replace(PhoneNumber, "-","")) FROM AddressBook;

update addressbook set PhoneNumber=Concat(if(length(PhoneNumber)< 10, "212", ""), replace(PhoneNumber, "-",""));

No comments:

Blog Archive