Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Script to alter data format

Posted on 2013-06-10
3
Medium Priority
?
314 Views
Last Modified: 2013-06-10
Currently have a column in the database that is char (20) in the following format
999-99-9999 to represent a phone number however this value needs to be imported into another database where the format is char (13) and shown as 999999999

Is there a sql script that can be run to remove the dashes from the column or to copy just the numbers from this column to a new column>
0
Comment
Question by:fireprograms_tech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 60

Expert Comment

by:HainKurt
ID: 39235968
select replace ('999-99-9999','-','')
999999999
0
 
LVL 10

Accepted Solution

by:
Banthor earned 2000 total points
ID: 39235978
There are too many possible answers.
update Table set [telcol] = replace([telcol],'-','') Will remove the dashs but will not validate the output.
you can use the statement as a select

SELECT
  replace([telcol],'-','')
from
  Table

and locate issues as

SELECT telcol, *
 from table
where 1=0
  or LEN(replace([telcol],'-','')   !=  9
  or isnumeric(replace([telcol],'-','') ) = 0
0
 

Author Closing Comment

by:fireprograms_tech
ID: 39236069
Thank you so much this completely resolved the issue I was having with the database,  I was able to create a new column and then run the update formula and move the edited data to the new column.  Thanks again!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question