Solved

Remove hyphens from column in SQL (Replace Instr)?

Posted on 2008-10-24
8
563 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
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 142

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
 
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…

914 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

19 Experts available now in Live!

Get 1:1 Help Now