Solved

How to replace dashes with spaces?

Posted on 2013-06-02
8
434 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
  • 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

813 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

10 Experts available now in Live!

Get 1:1 Help Now