Jul 3, 2006 #1 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!
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!
Jul 3, 2006 #2 SQLDenis Programmer Joined Oct 1, 2005 Messages 5,575 Location US 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:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/ Upvote 0 Downvote
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:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/
Jul 3, 2006 Thread starter #3 rds747 Technical User Joined Mar 8, 2005 Messages 180 Location US Thanks Denis Upvote 0 Downvote
Jul 3, 2006 #4 SQLDenis Programmer Joined Oct 1, 2005 Messages 5,575 Location US No problem Denis The SQL Menace SQL blog:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/ Upvote 0 Downvote
No problem Denis The SQL Menace SQL blog:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/