Solved

SQL Script to alter data format

Posted on 2013-06-10
3
310 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 52

Expert Comment

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

Accepted Solution

by:
Banthor earned 500 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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