Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting phone number

Status
Not open for further replies.

rds747

Technical User
Joined
Mar 8, 2005
Messages
180
Location
US
I have to format a phone number. This is what I have so far:

Select left(ltrim(CmPhone), 3) + '-' + right(rtrim(CmPhone), 7) as CmPhone From CusMast

How would I put a hypen between digit 6 and 7?

Thanks!
 
One way

Select left(ltrim(CmPhone), 3) + '-' + substring(ltrim(CmPhone), 4,3)+ '-' + right(rtrim(CmPhone), 4) as CmPhone
From CusMast

test script


Code:
create table #testp(CmPhone varchar(49))
insert #testp values('1112221234')
Select left(ltrim(CmPhone), 3) + '-' + substring(ltrim(CmPhone), 4,3)+ '-' + right(rtrim(CmPhone), 4) as CmPhone 
From #testp

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Thanks Denis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top