Solved

Remove hyphens from column in SQL (Replace Instr)?

Posted on 2008-10-24
8
573 Views
Last Modified: 2008-10-24
I have a column with inconsistent data.  Some fields have hyphens in the phone numbers, some do not.  I want to remove any hyphens from the column using SQL.

I've tried UPDATE MyTable SET [PhoneNumber] = Replace([PhoneNumber],"-","") ... and also with chr(45) instead... neither work.

0
Comment
Question by:NO_CARRIER
[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
8 Comments
 
LVL 9

Expert Comment

by:jamesgu
ID: 22796147
does those records show up when you do

select * from <your_table> where PhoneNumber like '*-*',


0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22796150
maybe it is not -, but ? ... you don't see the difference, but you might want to use ASC() function to find out the ascii code of the character you pass.
0
 
LVL 9

Accepted Solution

by:
CCongdon earned 50 total points
ID: 22796152
I'm not sure with Access, but I know in SQL Server the REPLACE function needs single quotes not double quotes to set your strings with.
Replace([PhoneNumber],'-','')  
0
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22796162
UPDATE MyTable SET [PhoneNumber] = Replace([PhoneNumber],"-","") is correct.

Perhaps the phone number isn't stored but it is applied as part of some output mask?
0
 
LVL 9

Expert Comment

by:CCongdon
ID: 22796279
Well, if double-quotes is correct for Access, then I'd go with Angelll's suggestion and check to see if it is a CHR(45) in there.
0
 
LVL 1

Author Comment

by:NO_CARRIER
ID: 22796331
james: yes, they all show.

ccong: that works! thanks...
0
 
LVL 9

Expert Comment

by:CCongdon
ID: 22796429
OK, well, the reason I mentioned the single quote thing is that I just ran into that problem on SQL 2005 yesterday, and that was what I finally figured out I was doing wrong. For the SQL server, the double quotes seemed to be trying to make the server do something with the table (I was getting the error Invalid Column Name ".") Glad to have been of help.
0
 
LVL 9

Expert Comment

by:jamesgu
ID: 22796483
the string in double quotes is considered as a column name in sql server,

thought double quotes works as single quotes in access as BrandonGalderis. strange
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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