?
Solved

remove padding from varchar fields

Posted on 2006-06-14
3
Medium Priority
?
1,188 Views
Last Modified: 2008-02-01
I just realized that I have a database with a few thousand records with unnecessary padding spaces in the fields fields.  I had to export from one DB then upload to MySQL, and didn't realize that the field values were exported with padding spaces.  

Anyway,  "Smith, John" is coming back from MySQL as "Smith            , John               ".  I put the results straight into HTML, so the extra spaces are ignored, and querying the DB with "Smith" still works . . . but I'd still like to clean up the fields.

Can anyone come up with an SQL statement I could plug into MySQL to strip the unecessary padding from the fields?  Unfortunately, I'm much more experienced with MS Access which, for all its shortcomings, has a handy expression builder for putting together scripts to do this kind of thing.
0
Comment
Question by:Zeek0
[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
3 Comments
 
LVL 30

Expert Comment

by:todd_farmer
ID: 16906296
Hi Zeek0,

if the first and last name come from different columns, wrap each column name in TRIM(columnname).

Cheers!
0
 
LVL 30

Accepted Solution

by:
todd_farmer earned 2000 total points
ID: 16906309
UPDATE table_name SET first_name=TRIM(first_name), last_name=TRIM(last_name);

would clean up existing entries.
0
 

Author Comment

by:Zeek0
ID: 16906404
Thanks.  I should have been able to figure that out myself, but you saved me some time sifting through help files/websites. :)
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

800 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