Solved

SQL Truncate

Posted on 2015-02-10
4
67 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
  • 2
4 Comments
 
LVL 45

Expert Comment

by:Vitor Montalvão
Comment Utility
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
Comment Utility
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 45

Accepted Solution

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

Open in new window

0
 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher earned 250 total points
Comment Utility
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Analysis of table use 7 26
Sql to find top3 for each record 7 15
backups - Strategies 1 12
How to simplify my SQL statement? 9 10
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now