SQL Server 2000: how do I return only the number from a phone number column

前端 未结 3 2007
耶瑟儿~
耶瑟儿~ 2021-01-19 16:49

I\'m trying to strip out the \"(\", \")\", \"-\", \"x\" or \"X\" \"ext\" and spaces from each phone number so I am left with only the first 10 digits or 1st 10 numbers of a

3条回答
  •  没有蜡笔的小新
    2021-01-19 17:35

    Another way to do it, if you didn't want to use a User Defined Function would be to use the REPLACE function, like so:

    SELECT Phone, REPLACE(REPLACE(REPLACE(REPLACE(Phone,' ',''),'(',''),')',''),'-','') AS NewPhone
    FROM Contacts
    

    Although its a bit klunky, it should serve your purpose.

提交回复
热议问题