btamulis 10/2/2023 9:08:52 AM

Format GP Phone Number in SQL

I need to format RM00101.PHONE1 field in GP as a normal looking Phone Number.

In RM00101 the PHONE1 field is a string field (21 characters)

Example - In the interface the end user typically sees (208)363-4562 ext 0000

In the table the value is 20836345620000

In my query I'm have a hard time converting to an integer and then formatting like a Phone Number.

If you try this (below) - you get sql error because the table is storing 14 characters for a phone number (last 4 are extension)

select FORMAT(CAST(RM00101.Phone1 AS int), '000-000-0000') as Phone1 from RM00101

How can i convert the 14 digits so I get a basic (xxx)-xxx-xxxx phone number? I don't need extension number even if it's stored in the database. 

Thanks in advance - Bron 

Version: All
Section: SQL Scripts


Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables
3