Re: TRIM Function does not remove trailing spaces from string
Posted in 2003
JeffC wrote:
> When using the following the trailing spaces are not removed from
> the string. Why does this not work properly?
>
> $ userid=$(echo "select trim(trailing ' ' from userid) as userid from
> table where userid = 'a1abcdef'" | dbaccess $DB 2>/dev/null | grep -vi
> user | sort -nr)
> $ echo "[${userid}]"
> [a1abcdef ]
> ^^^^> The spaces have not been trimmed in the result.
As others accurately diagnosed, what the engine taketh away, the tool
putteth back. Don't use DB-Access for this. Use SQLCMD from the IIUG
Software Archive:
$ userid=$(sqlcmd -d $DB "select trim(trailing ' ' from userid) asuserid from table where userid = 'a1abcdef'")
The reverse numeric sort in your version is curious - pourquoi? And
why not simply put an ORDER BY userid DESC in the SELECT?
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/