Skip to content
Advertisement

Format Phone Numbers With Characters

I need to format the existing phone numbers saved in my database. First, I need to clean the phone numbers with character.

should be:

After, I will format it to (3 digit area code) ###-#### Then disregard the ‘1’ country code for 11 digit numbers

I have tried

but when it comes to 1213-345-6789 ext 219, it includes 219. I am new to mssql.

Advertisement

Answer

You can try creating one more function to clean up any trailing number that comes after alphabets.

First, clean up any special character. Second, clean trailing numbers and alphabets.

  1. Function to remove Special Characters
  1. Function to remove trailing numbers and alphabets

Then you can call function on your column.

Edit:

This will remove the country code.

You can see example here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement