Solved

MSSQL 2000 select int column to display as phone number

Posted on 2009-04-09
2
314 Views
Last Modified: 2013-11-15
Right now I have a INT column (MSSQL 2000) called "homephone1" and when you put a number in it looks like this "5555555555".   How can I make it look like this "555-555-5555" or possibly "(555) 555-5555" without changing the actual data itself?

I need to avoid using any functions to do this, need to perhaps do this with replace?

Thanks for your help!
0
Comment
Question by:smyers051972
2 Comments
 
LVL 21

Accepted Solution

by:
JestersGrind earned 500 total points
ID: 24110406
You column has to be a BIGINT column because that number won't fit into INT, but all you have to do is some string manipulation like this.

Greg



DECLARE @num BIGINT
 
SET @num = 5555555555
 
SELECT '(' + SUBSTRING(CONVERT(VARCHAR, @num), 1, 3) + ') ' + SUBSTRING(CONVERT(VARCHAR, @num), 4, 3) + '-' + SUBSTRING(CONVERT(VARCHAR, @num), 7, 4)

Open in new window

0
 
LVL 1

Author Closing Comment

by:smyers051972
ID: 31568666
Thank you!
Was able to get that incorperated nicely!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Many to one in one row 2 38
T-SQL: Stored Procedure Syntax 3 30
Regarding Disk IO 3 42
Access #Deleted data 20 39
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

762 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