[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1192
  • 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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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