Find the place label
Connect to the database selected during installation. Supply digits only, including the international calling code. Longer matches take precedence over broad prefixes.
DECLARE @Digits varchar(20) = '13125551212';
SELECT TOP (1) FullPrefix, LocationText
FROM dbo.PhonePrefixGeography
WHERE Locale = 'en'
AND LEFT(@Digits, LEN(FullPrefix)) = FullPrefix
ORDER BY LEN(FullPrefix) DESC;
Find regions for one calling code
International calling codes are stored in dbo.PhoneCountryRegion. One calling code can serve several regions, so query all matching rows.
SELECT CallingCode,
RegionCode,
IsPrimaryRegion
FROM dbo.PhoneCountryRegion
WHERE CallingCode = '44'
ORDER BY IsPrimaryRegion DESC,
RegionCode;This returns the region or regions associated with calling code 44.
List every international calling code
The captured Google data contains 215 calling codes and 254 calling-code/region rows. Shared codes appear once for each associated region.
SELECT CallingCode,
RegionCode,
IsPrimaryRegion
FROM dbo.PhoneCountryRegion
ORDER BY TRY_CONVERT(int, CallingCode),
IsPrimaryRegion DESC,
RegionCode;IsPrimaryRegion identifies the first region Google assigns to a shared calling code. The package includes additional queries in Examples.sql.
Optional: add current country names
The installed Google data provides stable region identifiers such as GB, not country display names. If you need names as they exist today, load them into a separate, refreshable table and join on RegionCode. This optional table is not installed by the package.
CREATE TABLE dbo.PhoneRegionName
(
RegionCode varchar(3) NOT NULL,
Locale varchar(10) NOT NULL,
RegionName nvarchar(200) NOT NULL,
SourceName varchar(100) NOT NULL,
SourceAsOfDate date NOT NULL,
CONSTRAINT PK_PhoneRegionName
PRIMARY KEY (RegionCode, Locale)
);Use the current UN M49 Country or Area list for UN short names and ISO alpha-2 identifiers. For localized, interface-friendly names, use Unicode CLDR territory names. ISO explains how the codes are maintained in its ISO 3166 overview.
SELECT c.CallingCode,
c.RegionCode,
n.RegionName,
c.IsPrimaryRegion
FROM dbo.PhoneCountryRegion AS c
LEFT JOIN dbo.PhoneRegionName AS n
ON n.RegionCode = c.RegionCode
AND n.Locale = 'en'
WHERE c.CallingCode = '44';Handle 001 explicitly. In libphonenumber it represents a non-geographic service; UN M49 uses 001 for World. Store a package-specific label such as “Non-geographic service” instead of joining it to the UN World entry.
Record the source and as-of date with every load. Refresh country names independently from the pinned libphonenumber release because names and telephone assignments change on different schedules.