ken_masters — 2010-01-22T16:39:04-05:00 — #1
Is there an sql statement that will allow me to trim all leading and trailing spaces of all values in a table column?
philiptoop — 2010-01-22T16:51:03-05:00 — #2
UPDATE table set colname = TRIM(colname);
disgracian — 2010-01-22T18:40:30-05:00 — #3
What database are you using?
ken_masters — 2010-01-23T14:45:28-05:00 — #4
I'm using mysql 5.
Seems... UPDATE table set colname = TRIM(colname);
Isn't the right syntax. I'm doing the sql statement in phpmyadmin.
sjh — 2010-01-23T15:20:04-05:00 — #5
That is the correct syntax for MySQL. What error did it give you?
philiptoop — 2010-01-23T15:50:23-05:00 — #6
Update tablename set colname = TRIM(colname);
is the right syntax.
colname is the name of the column whose values you wish to remove leading and trailing spaces from and tablename is the name of the table in which the column resides.
ken_masters — 2010-01-23T15:58:29-05:00 — #7
Thanks Philip, I must have written it incorrectly but it works now... although no rows were affected, which is strange because I can see leading spaces in the majority of my rows in that column. I'm not sure how to get rid of them besides manually removing them.
sjh — 2010-01-23T16:31:06-05:00 — #8
I had a similar problem in the past - read the thread I posted for the solution
disgracian — 2010-01-23T20:04:05-05:00 — #9
Then why didn't you post this question in the MySQL section?
Mods, can we have this moved?
philiptoop — 2010-01-24T05:54:21-05:00 — #10
You could use the following
SELECT * from tablename where colname like ' %' or colname like '% ';
to see if any columns with leading or trailing spaces are reported.
I am wondering if the character is not a space but is being seen as a space.