Solved

SQL Truncate

Posted on 2015-02-10
4
81 Views
Last Modified: 2015-03-24
Hello.

I need to trim a column of phone numbers to remove spaces and truncate to 20 numbers.

Number range includes.

xxx xxxxxxxxx
xxxxxxxxxxxxx
xxxxx xxxxxxx
xxxx xxxx xxx

thanks.
0
Comment
Question by:aneilg
[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
  • 2
4 Comments
 
LVL 50

Expert Comment

by:Vitor Montalvão
ID: 40600278
What is the data type of the field?
Which spaces do you want to remove (left, right, middle)?
Can you give us an example of current data and the expected results?
0
 

Author Comment

by:aneilg
ID: 40600356
Hello.

Data Type Varchar(23)

Its to remove any spaces in the phone field.

Now             xxx xxxxxx
Result          xxxxxxxxx

Now             xxxx xxxxx
Result          xxxxxxxxx

thanks.
0
 
LVL 50

Accepted Solution

by:
Vitor Montalvão earned 250 total points
ID: 40600367
You can use the REPLACE function:
SELECT REPLACE(PhoneNumberFieldName, ' ', '')

Open in new window

0
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 250 total points
ID: 40600787
SELECT LEFT(REPLACE(PhoneNumberFieldName, ' ', ''), 20) --and truncate to 20 "numbers"

Q: Do you need/want to check for specifically "numbers" in the column?  Do you want to strip all non-numerics?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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