A quick and dirty way would be:
Select
CONVERT
(
BIGINT,
REPLACE
(
REPLACE
(
REPLACE
(
REPLACE
(
Customer_Telephone_Number,
' ',--Replace white spaces
''
),
'-',--Replace dashes
''
),
'(',--Replace open parenthesis
''
),
')',--Replace close parenthesis
''
)
)
from
DATABASE_2.DBO.CUSTOMER_TABLE
You can run the following in order to see other potential characters:
select Customer_Telephone_Number
from DATABASE_2.DBO.CUSTOMER_TABLE
where ISNUMERIC
(
REPLACE
(
REPLACE
(
REPLACE
(
REPLACE
(
Customer_Telephone_Number,
' ',--Replace white spaces
''
),
'-',--Replace dashes
''
),
'(',--Replace open parenthesis
''
),
')',--Replace close parenthesis
''
)
) = 0
This will give you a list of telephone numbers that cannot get converted to BIGINT
. Check why (for instance if they have a .
in them) and add these characters in the REPLACE as i did in the example.