• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1197
  • Last Modified:

remove padding from varchar fields

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
Zeek0
Asked:
Zeek0
  • 2
1 Solution
 
todd_farmerCommented:
Hi Zeek0,

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

Cheers!
0
 
todd_farmerCommented:
UPDATE table_name SET first_name=TRIM(first_name), last_name=TRIM(last_name);

would clean up existing entries.
0
 
Zeek0Author Commented:
Thanks.  I should have been able to figure that out myself, but you saved me some time sifting through help files/websites. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now