how to add one space before and at end of a field in table
Moderator: General Moderators
-
mayanktalwar1988
- Forum Contributor
- Posts: 133
- Joined: Wed Jul 08, 2009 2:44 am
how to add one space before and at end of a field in table
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.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: how to add one space before and at end of a field in ta
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]
[text]UPDATE `table_name` SET `field_name` = CONCAT(' ', field_name, ' ')[/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
mayanktalwar1988
- Forum Contributor
- Posts: 133
- Joined: Wed Jul 08, 2009 2:44 am
Re: how to add one space before and at end of a field in ta
its a workaround to make some query run faster..thanks
-
mayanktalwar1988
- Forum Contributor
- Posts: 133
- Joined: Wed Jul 08, 2009 2:44 am
Re: how to add one space before and at end of a field in ta
hey also tell me the opposite one for backup ....removing the added spaces.. opposite for above query 
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: how to add one space before and at end of a field in ta
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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
mayanktalwar1988
- Forum Contributor
- Posts: 133
- Joined: Wed Jul 08, 2009 2:44 am
Re: how to add one space before and at end of a field in ta
ok thanks your query worked