Page 1 of 1
how to add one space before and at end of a field in table
Posted: Wed Jul 21, 2010 12:15 pm
by mayanktalwar1988
is there any possible query to add just one space both at the start and at the end in one of field of a table..i want to do for all the rows in a particular field...anyone has a query for that in sql then plz share.
Re: how to add one space before and at end of a field in ta
Posted: Wed Jul 21, 2010 12:20 pm
by AbraCadaver
I can't think of any possible reason for doing this in the database, but if you're using mysql:
[text]UPDATE `table_name` SET `field_name` = CONCAT(' ', field_name, ' ')[/text]
Re: how to add one space before and at end of a field in ta
Posted: Wed Jul 21, 2010 12:26 pm
by mayanktalwar1988
its a workaround to make some query run faster..thanks
Re: how to add one space before and at end of a field in ta
Posted: Wed Jul 21, 2010 12:30 pm
by mayanktalwar1988
hey also tell me the opposite one for backup ....removing the added spaces.. opposite for above query

Re: how to add one space before and at end of a field in ta
Posted: Wed Jul 21, 2010 12:33 pm
by AbraCadaver
For leading and trailing spaces use TRIM(). For other characters you'll use some string function to return just the part that you want:
http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html
Re: how to add one space before and at end of a field in ta
Posted: Wed Jul 21, 2010 12:37 pm
by mayanktalwar1988
ok thanks your query worked