MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 22nd, 2004, 11:45 AM
jmlsgateway jmlsgateway is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: OKC
Posts: 342 jmlsgateway User rank is Private First Class (20 - 50 Reputation Level)jmlsgateway User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 20 h 48 m 28 sec
Reputation Power: 5
Format a string

I have a column in a database that is a phone number. The problem is that it is stored like so

4589958

Anyway that I can insert a "-" after the first 3 digits in SQL SELECT statement

Reply With Quote
  #2  
Old October 22nd, 2004, 12:45 PM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,322 bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 46 m 5 sec
Reputation Power: 23
Send a message via AIM to bocmaxima
SELECT (SUBSTRING(PHONE,0,3)+'-'+SUBSTRING(PHONE,4,7)) AS PHONENUM
FROM Table

Reply With Quote
  #3  
Old October 22nd, 2004, 12:53 PM
cmv131 cmv131 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 33 cmv131 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 3 h 41 m 24 sec
Reputation Power: 5
Something like this should work as long as they are all in that format
Code:
to select --
SELECT Left(column1,3)+'-'+Right(column1,4) AS column1
FROM table1;

to update--
update table1 
set a = LEFT(column1,3) + '-' + right (column1,4)

Reply With Quote
  #4  
Old October 22nd, 2004, 02:29 PM
jmlsgateway jmlsgateway is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: OKC
Posts: 342 jmlsgateway User rank is Private First Class (20 - 50 Reputation Level)jmlsgateway User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 20 h 48 m 28 sec
Reputation Power: 5
Thanks for the response, I was trying SUBSTR instead of Substring!

Works Great!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Format a string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT