Re: TRIM Function does not remove trailing spaces from string
Posted in 2003
The trailing spaces are being removed by the engine but dbaccess is
displaying output in columnur format with column headings so it actually
makes the column width the greater of the column name or the column width.
In your case it would appear you have a column data type of either char(12)
or varchar(12).
One possible way to fix this is to cast the userid column to char with a
length greater than 80. Doing this will force dbaccess to write all the
column value pairs as rows. You can then use cut to get rid of the column
label leaving only the trimmed value.
The following should work for you.
$ userid=$(echo "select trim(trailing ' ' from userid::char(100)) from
table where userid = 'a1abcdef'" | dbaccess $DB 2>/dev/null | grep -vi user
| sort -nr | cut -c15- )
$ echo "[${userid}]'"
[a1abcdef]
You could also use your original example and pass the output from sort -nr
to a utility that trims lines from stdin.
Hope this helps.
Sincerely,
Gregg Walker
"JeffC" <gninnacj@netscape.net> wrote in message
news:c703eed2.0306190725.c49721a@posting.google.com...
> Hi,
>
> 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.
>
> Regards,
> Jeff