UFN_PHONE_GETINTERNATIONALNUMBER

Functions returns the fully formatted international number if a country code exists for the given country.

Return

Return Type
nvarchar(110)

Parameters

Parameter Parameter Type Mode Description
@COUNTRYID uniqueidentifier IN
@NUMBER nvarchar(100) IN

Definition

Copy


create function dbo.UFN_PHONE_GETINTERNATIONALNUMBER
(
    @COUNTRYID uniqueidentifier,
    @NUMBER nvarchar(100)
)
returns nvarchar(110)
with execute as caller
as begin
    declare @INTERNATIONALNUMBER nvarchar(120);
    declare @COUNTRYCODE nvarchar(10);

    select 
        @COUNTRYCODE = COUNTRYCODE
    from dbo.COUNTRY
    where ID = @COUNTRYID;

    if len(@COUNTRYCODE) > 0 
        set @INTERNATIONALNUMBER = '+' + @COUNTRYCODE + ' ' + @NUMBER;
    else
        set @INTERNATIONALNUMBER = @NUMBER;

    return @INTERNATIONALNUMBER;
end