Converting chars to ints
Posted in 2000
Topics: Server Administration
I have a char field that contains numbers (they are initially scanned so are
stored as chars). In dbaccess can I convert them to ints so I can SUM them.
Currently I output them and sum them with awk.
Cheers
darkemperor_uk wrote:
> I have a char field that contains numbers (they are initially scanned so are
> stored as chars). In dbaccess can I convert them to ints so I can SUM them.
> Currently I output them and sum them with awk.
As long as you're confident that the scanners don't generate non-numeric
data (ever), you should be able to do:
SELECT SUM(char_col + 0) ...
--
Yours,
Jonathan Leffler (Jonathan.Leffler@Informix.com) #include <disclaimer.h>
Guardian of DBD::Informix v1.00.PC1 -- http://www.perl.com/CPAN
"I don't suffer from insanity; I enjoy every minute of it!"
darkemperor_uk wrote:
>
> I have a char field that contains numbers (they are initially scanned so are
> stored as chars). In dbaccess can I convert them to ints so I can SUM them.
> Currently I output them and sum them with awk.
> Cheers
Strangely as long as NONE of the rows that are fetched contain any
non-numeric characters just:
SELECT keycol, SUM( numeric_string_col )
FROM mytable
GROUP BY 1
ORDER BY 1;
Informix automagic!
Art S. Kagel