-2

I have phone number field in either of these two formats (xxx)xxxxxxx or (xxx)xxx-xxxx

I want to extract and format the number as xxxxxxxxxx, number only. Is there a simple way in sql select statement?

  • 2
    Possible duplicate of [Query to get only numbers from a string](https://stackoverflow.com/questions/16667251/query-to-get-only-numbers-from-a-string) – Bob Kaufman Jul 07 '17 at 20:40

2 Answers2

0

It is always difficult to answer coding questions without an example of the code with which you are working. That being said, something like this might be what you are look for:

SELECT
[Phone Numbers]
,FORMAT([Phone Numbers],'(##########') AS [Formatted Phone]
FROM tbl_sample
Matt Jackson
  • 158
  • 9
0
SELECT 
column_sample,
REPLACE(REPLACE(REPLACE(phone , '(', '') , ')', '') , '-', '') as phone
FROM tbl_sample;
Kemal Güler
  • 608
  • 1
  • 6
  • 21