Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Formatting Output

Author  Topic 

ewade
Starting Member

36 Posts

Posted - 2002-10-10 : 15:02:39
Quick and easy question, which I ask only because my SQL server documentation was confiscated by our network analyst and I'm more familiar with the way that this is done on Oracle:

How can I format results from a query? Specifically, I have a numeric field that contains a 10-digit phone number. I'd like to turn 9995551212 into (999) 555-1212 on the output side.



Never stop learning!

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-10-10 : 15:11:38
Usually, data formatting should be done on the display layer ...


declare @p decimal
select @p = 9995551212

select
'(' + left(convert(varchar,@p),3) + ') ' +
substring(convert(varchar,@p),4,3) + '-' +
substring(convert(varchar,@p),6,4)

 


Jay White
{0}
Go to Top of Page
   

- Advertisement -