SQL-从电话号码中删除括号 [英] SQL - Remove Parenthesis from Phone Number

查看:71
本文介绍了SQL-从电话号码中删除括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从数字的区号中删除括号.我可以这样做,但是当我尝试连接两个替换函数时,数字重复,只删除了一个括号.

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

http://i.imgur.com/4iJoFzE.png

推荐答案

不要添加嵌套

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 ''.

这篇关于SQL-从电话号码中删除括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆