你可以創建一個功能,你可以通過你的手機號碼,它會返回你的區號。
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點的例子嗎? –