是否可以根据国家/地区字段的值创建一个将电话号码(+44)分配给手机号码的功能。
答案 0 :(得分:1)
您可以从此处https://countrycode.org/
窃取国家/地区代码/国家/地区列表使用此数据创建新表。看起来像:
Country | Country_Code
然后,我怀疑,你有一张类似于:
的表格 Something | Phone_Number | Country
您现在只需要一些SQL将它放在一起(而不是函数):
SELECT existing_table.something, new_table.Country_code + " " + existing_table.phone_number
FROM existing_table
JOIN new_table ON existing_table.country = new_table.country
鲍勃是你的叔叔。
答案 1 :(得分:1)
您可以从此处https://countrycode.org/窃取国家/地区代码/国家/地区列表,并使用“标识”列为其分配国家/地区ID。
使用此数据创建新表。看起来像:
Country | Country_Code | Country_ID
然后,我怀疑,你有一张类似于:
的表格 Something | Phone_Number | Country | Country_ID
对现有表进行更改以添加Country_ID,以提高性能:
ALTER TABLE existing_table
ADD country_id int;
UPDATE e
SET e. country id = n.country_id
FROM existing_table e
JOIN new_table n
ON e.country = n.country
您现在只需要一些SQL将它放在一起(而不是函数):
SELECT e.something,
FORMAT(CONCAT(n.country_code,' ', e.phone_number), '###-##-####') AS CompletePhone
FROM existing_table e
JOIN new_table n
ON e.country_id = n.country_id