Convert Char-->integer or Integer-->char
Posted in 2003
Topics: General Discussion
Hello,
I am a new bee with informix and I want to convert an integer to char or a
char to integer.
Informix 7+ CSDK + PHP
My problems is the attribute type is different. toto: type char(30) and titi
type integer but the data are the same (bad conception..)
I try :
select toto,titi
from table1,table2
where table1.titi=cast (table2.toto as integer)
---> error -201
select toto,titi
from table1,table2
where table1.titi=table2.toto::integer
--> error -201
I couldn't modifiy my database. Have you got an idea ???
Thanks you very much for your help
"victor" wrote
> select toto,titi
> from table1,table2
> where table1.titi=cast (table2.toto as integer)>
> ---> error -201
>
> select toto,titi
> from table1,table2
> where table1.titi=table2.toto::integer>
> --> error -201
>
> I couldn't modifiy my database. Have you got an idea ???
> Thanks you very much for your help
>
why do you have comma in the select statement's toto,titi?
perhaps the following would help:
select toto.titi
from table1,table2
where table1.titi=table2.toto
MT?
Because I have an error :
toto is colomun type char(30)
and titi is annother column type integer
Bye
"Mladen Turk" <mturk_NOSPAM_@apache.org> a 'crit dans le message de
news:bqaqgo$un6$1@sunce.iskon.hr...
>
> "victor" wrote
>
> > select toto,titi
> > from table1,table2
> > where table1.titi=cast (table2.toto as integer)> >
> > ---> error -201
> >
> > select toto,titi
> > from table1,table2
> > where table1.titi=table2.toto::integer> >
> > --> error -201
> >
> > I couldn't modifiy my database. Have you got an idea ???
> > Thanks you very much for your help
> >
>
> why do you have comma in the select statement's toto,titi?
> perhaps the following would help:
>
> select toto.titi
> from table1,table2
> where table1.titi=table2.toto>
>
> MT?
>
>
victor wrote:
> I am a new bee with informix and I want to convert an integer to char or a
> char to integer.
> Informix 7+ CSDK + PHP
Informix Dynamic Server (IDS) 7.x does not support explicit casting.
Have you considered moving to IDS 9.x which does?
> My problems is the attribute type is different. toto: type char(30) and titi
> type integer but the data are the same (bad conception..)
> I try :
>
> select toto,titi
> from table1,table2
> where table1.titi=cast (table2.toto as integer)>
> ---> error -201
>
> select toto,titi
> from table1,table2
> where table1.titi=table2.toto::integer>
> --> error -201
>
> I couldn't modify my database.
Why not? It is badly broken in design. It needs an overhaul.
> Have you got an idea ???
As Mark Stock indicated, you can usually get an implicit conversion to
work. When you need an explicit conversion from INTEGER to CHAR, use
"intcol || ''", and when you need an explicit conversion from CHAR to
INTEGER use "+ 0". Note that if you have fancy formatting of your
CHAR values (such as leading zeroes), you should coerce to INTEGER
rather than to CHAR to avoid mis-formatting problems.
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/