Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Remove extra spaces from database column

Posted on 2007-12-05
2
Medium Priority
?
2,590 Views
Last Modified: 2013-12-12
I have a MySQL table that contains thousands of records that have one major problem.  Specifically the data in a VARCHAR column has multiple spaces in between words.  I have seen anywhere from the correct single space up to four spaces in between words.  This data came from a speadsheet and this problem wasn't caught until it's too late to re-import.  Anyone know how I could update the records to remove any 2 or more spaces?

Thanks in advance.
0
Comment
Question by:expertis
[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
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 20414235
please run the following statement until you get "0 rows affected"
UPDATE yourtable
  SET yourfield = REPLACE(yourfield, '  ' , ' ' )
WHERE yourfield LIKE '%  %'

Open in new window

0
 

Author Closing Comment

by:expertis
ID: 31412941
Thank you!!! This worked without any issues.  
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

719 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