Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MSSQL 2000 select int column to display as phone number

Posted on 2009-04-09
2
Medium Priority
?
345 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
JestersGrind earned 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

618 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