Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Format column Expand / Collapse
Author
Message
Posted Tuesday, June 3, 2008 4:40 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, January 15, 2014 3:17 PM
Points: 61, Visits: 87
Hi
I am trying to format a col (phone) in a table (prob thru a UDF).
from 1234567890 to 123-456-7890.
Any help
Thanks
Post #511024
Posted Tuesday, June 3, 2008 5:05 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Thursday, July 17, 2014 12:14 PM
Points: 4,386, Visits: 9,501
Here is one way (of many):

Declare @len int;
Declare @value varchar(10);

--Set @value = '4567890';
Set @value = '1234567890';
Set @len = len(@value);

Select @value, stuff(stuff(right('000' + @value, 10), 7, 0, '-'), 4, 0, '-');

Jeff


Jeffrey Williams
Problems are opportunites brilliantly disguised as insurmountable obstacles.

How to post questions to get better answers faster
Managing Transaction Logs
Post #511033
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse