Solved

MSSQL 2000 select int column to display as phone number

Posted on 2009-04-09
2
258 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
Comment Utility
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
Comment Utility
Thank you!
Was able to get that incorperated nicely!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

744 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

16 Experts available now in Live!

Get 1:1 Help Now