Solved

Remove hyphens from column in SQL (Replace Instr)?

Posted on 2008-10-24
8
561 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

708 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

14 Experts available now in Live!

Get 1:1 Help Now