Solved

Remove hyphens from column in SQL (Replace Instr)?

Posted on 2008-10-24
8
566 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 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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 …
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

839 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