I wanted to know if there is a better way of writing this Update.
update Alumni_Export_New
set phone = replace(replace(replace(replace(phone,'-',''),' ',''),')',''),'(','')
from tbl
I have a stored procedure in MSSQL 2005 to clean the phone field in a table and thought there should be a better way of doing this then what I have.
Use CLR integration and Regular Expressions.
You can consider putting the replace logic in a user defined function if you really don't like the look the REPLACE and if you don't mind a performance hit. Otherwise, what you have is probably your best solution.
Sample:
UPDATE Alumni_Export_New
SET phone = dbo.StripPhoneNumber(phone)
FROM tbl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With