比较电话号码sql

编程入门 行业动态 更新时间:2024-10-26 07:24:45
本文介绍了比较电话号码sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 2 个不同的表中有 2 组电话号码,table 1 具有 01234567890 的直接格式,另一个表有 3 种不同的格式,有时是 01234567890 或 01234 567890 或 01234-567890.

I have 2 sets of phone numbers in 2 different tables, table 1 has the straight forward format of 01234567890 and the other table has 3 different formats, sometimes it's 01234567890 or 01234 567890 or 01234-567890.

目前我只是对表进行内部联接,只返回几行,但希望更多,因为显然联接中会遗漏任何带有连字符或空格的内容.

Currently I'm just doing an Inner join on the tables and only get a few rows returned but would expect more as obviously anything with a hyphen or space will get missed from the join.

系统的方式我无法更改具有 3 种格式的表格中的数据,因此无法对其进行标准化或清除等.

The way the system is I can't change the data in the table with 3 formats so can't standardise it or clean it out etc.

解决这个问题的最佳方法是什么?

What would be the best way to tackle this?

推荐答案

好吧,您可以考虑在您的第二个表中创建一个计算列来规范化电话号码格式 - 类似于:

Well you could think about creating a computed column in your second table to normalize the phone number format - something like:

ALTER TABLE dbo.YourSecondTable ADD NormalizedPhone AS REPLACE(REPLACE(PhoneColumn, '-', ''), ' ', '') PERSISTED

此表达式从 PhoneColumn 中删除任何空格和任何破折号,并将这些值存储在名为 NormalizedPhone 的新计算列中.

This expression removes any spaces and any dashes from the PhoneColumn and those values are stored in a new, computed column called NormalizedPhone.

此列将始终保持最新 - 即使您稍后更改了 PhoneColumn 的值.它将始终包含标准化电话号码自动.

This column will always be kept up to date - even if you change your PhoneColumn's value later on. It will always contain the normalized phone number automagically.

现在您可以轻松地将规范化电话字符串的两个表连接起来,并且您应该得到更准确的结果.

Now you can easily join the two tables on the normalized phone strings, and you should get more accurate results.

更多推荐

比较电话号码sql

本文发布于:2023-10-27 22:38:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534760.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电话号码   sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!