Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Phone Number Format with extension in DB2

Posted on 2014-03-14
5
Medium Priority
?
1,320 Views
Last Modified: 2014-03-17
Hi,

   We are on DB2 UDB 9.7.
  I want to write a SQL to format the phone number and extension to display the following format. My current format is : Phone Number: 5555555555 and extension in the format: 1234.
Please help.
(555) 555-5555 Ext. 1234

Open in new window

0
Comment
Question by:pvsbandi
  • 2
  • 2
5 Comments
 
LVL 27

Expert Comment

by:tliotta
ID: 39930622
...to format the phone number and extension...

You showed us the presentation format that you want to see, but you didn't tell us anything about the data type(s?) and size(s?) of the column(s?) in your database. What is being formatted? What is the column definition? Is it numeric or character? How big?

Tom
0
 

Author Comment

by:pvsbandi
ID: 39935405
Sorry..here is the information.

   Two columns in my database: STAFF.Work_PHONE_TX is a varchar(10).
                                                   STAFF.Work_Phone_EXTN_TX is a varchar(5).

If STAFF.Work_PHONE_TX = '5555555555' and STAFF.Work_Phone_EXTN_TX = '1234', then i want the format to be displayed as (555) 555-5555 Ext. 1234
0
 
LVL 18

Accepted Solution

by:
Dave Ford earned 2000 total points
ID: 39935422
This ought to do it:

select '(' ||
       substr(Work_PHONE_TX,1,3) ||
       ') ' ||
       substr(Work_PHONE_TX,4,3) ||
       '-' ||
       substr(Work_PHONE_TX,7,4) ||
       ' Ext. ' ||
       Work_Phone_EXTN_TX as formattedPhone                  
  from deleteme

Open in new window


HTH,
DaveSlash
0
 

Author Closing Comment

by:pvsbandi
ID: 39935532
Thank you! works as expected.
0
 
LVL 27

Expert Comment

by:tliotta
ID: 39935788
There is one minor potential problem. The STAFF.Work_PHONE_TX column is VARCHAR, so the column expects values that might have fewer than 10 characters. If it should be expected always to have 10 significant characters, the presentation possibly should ensure that the characters are always right-justified in a CHAR(10) intermediate field.

Tom
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question