Solved

Phone Number Format with extension in DB2

Posted on 2014-03-14
5
1,153 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:
daveslash earned 500 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now