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
 General SQL Server Forums
 New to SQL Server Programming
 How to remove dashes from phone number

Author  Topic 

jatrix32
Starting Member

49 Posts

Posted - 2010-08-31 : 12:05:58
I have a category that has users phone numbers as so: 333-333-3333

I want to run an update query so all those phone number are converted to read: 3333333333

I am new to SQL, like just started today. How do I go about doing this?
And, what is a good SQL resource to go to for learning it?

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-08-31 : 12:08:03
Hi jatrix.

Best resource I ever found was this site!

As long as you ask sensible questions you'll do fine.

Also -- the inbuilt help for sql server is really good. Just press F1 in management studio

To replace - in a string use REPLACE

Example

DECLARE @foo VARCHAR(255)
SET @foo = '123-123-3333'

SELECT REPLACE(@foo, '-', '')



Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

jatrix32
Starting Member

49 Posts

Posted - 2010-08-31 : 12:10:59
Thanks Charlie, I am really new to this. I am not sure what you mean with the code you entered. I am the definition of an SQL noob.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-31 : 12:23:51
If you want to UPDATE your table with phone numbers without dashes:

update your_table
set your_phone_column = replace(your_phone_column,'-','')
where your_phone_column like '%-%'

If you want to SELECT the data without making changes in the table:

select replace(your_phone_column,'-','') as your_phone_column
from your_table


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jatrix32
Starting Member

49 Posts

Posted - 2010-08-31 : 12:34:55
THANK YOU THANK YOU THANK YOU!!!!!!!!

That worked!!!

And I am going to use the resources that where suggested above to learn SQL.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-31 : 12:42:34
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -