你可以创建一个功能,你可以通过你的手机号码,它会返回你的区号。
CREATE FUNCTION [dbo].[f_GetAreaCode]
(
@phoneNumber as nvarchar(200)
)
RETURNS nvarchar(50)
AS
BEGIN
-- Declare the return variable here
DECLARE @areaCodeAbbr as nvarchar(50)
-- Add the T-SQL statements to compute the return value here
if Exists(select 1 from sys.tables where @phoneNumber like '1-%' or @phoneNumber like '1(%') or @phoneNumber like '1 %')
set @phoneNumber = RIGHT(@phoneNumber,len(@phoneNumber)-2)
set @phoneNumber = replace(@phoneNumber,'(','')
set @phoneNumber = replace(@phoneNumber,')','')
set @phoneNumber = replace(@phoneNumber,'-','')
set @phoneNumber = LTRIM(@phoneNumber)
SELECT
@areaCodeAbbr = left(@phoneNumber,3)
-- Return the result of the function
RETURN @areaCodeAbbr
END
调用的函数写像SQL -
Select dbo.f_GetAreaCode('(201) 411-5200x4002')
你能告诉我们什么正确的结果是你给敬请6点的例子吗? –