Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - Remove Parenthesis from Phone Number

I'm trying to remove parenthesis from the area code of a number. I'm able to do so but when I try to concatenate the two Replace functions, the numbers repeat with only one parenthesis removed.

This is what I tried so far:

SELECT HomePhone, REPLACE(HomePhone, '(', '') + 
REPLACE(HomePhone, ')', '') AS Expr1
FROM dbo.Employees

https://i.sstatic.net/pwsyj.png

like image 646
user3465386 Avatar asked Dec 03 '25 10:12

user3465386


1 Answers

Nest don't add

Replace(Replace(HomePhone,')',''),'(','')

Look at how the function replace works. It expects string With Text To Evaluate, string to replace, string to replace with)

By adding them you should be getting the number listed twice, but if the data type isn't long enough it may be truncating values. by nesting you're telling the system to replace the ) and then use that string w/o the ) to have the ( replaced with ''.

like image 84
xQbert Avatar answered Dec 06 '25 01:12

xQbert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!