?
Solved

How to replace dashes with spaces?

Posted on 2013-06-02
8
Medium Priority
?
452 Views
Last Modified: 2013-06-02
My table Populations has a column named City.
 
About 1000 entries for "City" contain city names that have dashes in them.
I want to replace all dashes with spaces.  How can I quickly write a query that selects all city like '%-%' and update them with a space to replace the dash?  Thank you!
0
Comment
Question by:arthurh88
[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
  • 5
  • 2
8 Comments
 
LVL 7

Expert Comment

by:Ross Turner
ID: 39213993
Try this
Replace(city,'-',' ')
0
 
LVL 7

Expert Comment

by:Ross Turner
ID: 39213994
Once you happy with a select
Replace(city,'-',' ')

You could do an update

Update your table
Set city = Replace(city,'-',' ')

That should get you sorted
0
 

Author Comment

by:arthurh88
ID: 39213999
how do i do the select statement and the replace together?  im not sure how to word a select and an update at the same time, i want to both select all instances of city that contain a dash and then update the record to replace the dash with space.
0
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 
LVL 16

Accepted Solution

by:
Surendra Nath earned 2000 total points
ID: 39214004
There is no need to do a select, if you want to do an update here.
this should do it

Update <your table>
Set city = Replace(city,'-',' ')

Open in new window

0
 
LVL 7

Expert Comment

by:Ross Turner
ID: 39214007
Below will find all - and return
And show original and replaced

Select
City as originalcity,
Replace(city,'-',' ') as replacedcityname
From yourtable
Where city like '%-%'

Then once your happy create a new query to update youtable
Set city = Replace(city,'-',' ')
Where city like '%-%'
0
 
LVL 7

Expert Comment

by:Ross Turner
ID: 39214010
Hey Neo_jarvis i thought it would be better to let him see what he changing before changing..... Then go into an update.

But indeed you can bowl straight into the update statement... If your confident it going to give you the right outcome.
0
 

Author Closing Comment

by:arthurh88
ID: 39214014
wow how easy was that.   thanks....i guess I should have figured that out, but I will know next time.  perfect
0
 
LVL 7

Expert Comment

by:Ross Turner
ID: 39214032
Errr I gave the same solution in post 2 and not even shared points ????
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

752 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