This is a discussion on Re: Convert Char-->integer or Integer-->char within the Informix forums, part of the Database Server Software category; --> victor wrote: > Hello, > > I am a new bee with informix and I want to convert an ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| victor wrote: > 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 Have you tried: SELECT toto, titi FROM table1, table2 WHERE table1.titi = table2.toto The cast should be implicit in any version. Performance may not be optimum, but that's down to your "bad conception". ;-) To return an INT value, use: SELECT toto+0, titi or SELECT toto::INT, titi Cheers, -- Mark. +----------------------------------------------------------+-----------+ | Mark D. Stock mailto:mdstock@MydasSolutions.com |//////// /| | Mydas Solutions Ltd http://MydasSolutions.com |///// / //| | +-----------------------------------+//// / ///| | |We value your comments, which have |/// / ////| | |been recorded and automatically |// / /////| | |emailed back to us for our records.|/ ////////| +----------------------+-----------------------------------+-----------+ sending to informix-list |
| |||
| Thank you very much, I'll try this, this week Bye Victor "Mark D. Stock" <mdstock@mydassolutions.com> a écrit dans le message de news:bqb5lt$t7u$1@terabinaries.xmission.com... > > victor wrote: > > > 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 > > Have you tried: > > SELECT toto, titi > FROM table1, table2 > WHERE table1.titi = table2.toto > > The cast should be implicit in any version. Performance may not be optimum, > but that's down to your "bad conception". ;-) > > To return an INT value, use: > > SELECT toto+0, titi > > or > > SELECT toto::INT, titi > > Cheers, > -- > Mark. > > +----------------------------------------------------------+-----------+ > | Mark D. Stock mailto:mdstock@MydasSolutions.com |//////// /| > | Mydas Solutions Ltd http://MydasSolutions.com |///// / //| > | +-----------------------------------+//// / ///| > | |We value your comments, which have |/// / ////| > | |been recorded and automatically |// / /////| > | |emailed back to us for our records.|/ ////////| > +----------------------+-----------------------------------+-----------+ > > sending to informix-list |
| |||
| Hi, I have tried, but I have an error 1213. I think I am wrong somewhere. Here is my tables : Tables textos : textos type codigo char(30) With codigo = 1, 15,20,34 etc... Table Lots : Lots type lot integer with lots.lot = 1,15,20,34 etc ... I need this "request" select textos.codigo from textos,lots where textos.codigo=lots.lot; This don't work it is normaly because type is different So as you say I try this: select textos.codigo+0 from textos,lots where textos.codigo=lots.lot So I have an 1213 error --> A character to numeric conversion process failed. I try : select textos.codigo::INT from textos,lots where textos.codigo=lots.lot So I have an 201 error --> Syntaxe error as occurred Have you got an explication ?? Thanks for your help. Victor "Mark D. Stock" <mdstock@mydassolutions.com> a écrit dans le message de news:bqb5lt$t7u$1@terabinaries.xmission.com... > > victor wrote: > > > 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 > > Have you tried: > > SELECT toto, titi > FROM table1, table2 > WHERE table1.titi = table2.toto > > The cast should be implicit in any version. Performance may not be optimum, > but that's down to your "bad conception". ;-) > > To return an INT value, use: > > SELECT toto+0, titi > > or > > SELECT toto::INT, titi > > Cheers, > -- > Mark. > > +----------------------------------------------------------+-----------+ > | Mark D. Stock mailto:mdstock@MydasSolutions.com |//////// /| > | Mydas Solutions Ltd http://MydasSolutions.com |///// / //| > | +-----------------------------------+//// / ///| > | |We value your comments, which have |/// / ////| > | |been recorded and automatically |// / /////| > | |emailed back to us for our records.|/ ////////| > +----------------------+-----------------------------------+-----------+ > > sending to informix-list |
| |||
| Hi Mark, I have tried, but I have an error 1213. I think I am wrong somewhere. Here is my tables : Tables textos : textos type codigo char(30) With codigo = 1, 15,20,34 etc... Table Lots : Lots type lot integer with lots.lot = 1,15,20,34 etc ... I need this "request" select textos.codigo from textos,lots where textos.codigo=lots.lot; This don't work it is normaly because type is different So as you say I try this: select textos.codigo+0 from textos,lots where textos.codigo=lots.lot So I have an 1213 error --> A character to numeric conversion process failed. I try : select textos.codigo::INT from textos,lots where textos.codigo=lots.lot So I have an 201 error --> Syntaxe error as occurred Have you got an explication ?? Thanks for your help. Victor "Mark D. Stock" <mdstock@mydassolutions.com> a écrit dans le message de news:bqb5lt$t7u$1@terabinaries.xmission.com... > > victor wrote: > > > 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 > > Have you tried: > > SELECT toto, titi > FROM table1, table2 > WHERE table1.titi = table2.toto > > The cast should be implicit in any version. Performance may not be optimum, > but that's down to your "bad conception". ;-) > > To return an INT value, use: > > SELECT toto+0, titi > > or > > SELECT toto::INT, titi > > Cheers, > -- > Mark. > > +----------------------------------------------------------+-----------+ > | Mark D. Stock mailto:mdstock@MydasSolutions.com |//////// /| > | Mydas Solutions Ltd http://MydasSolutions.com |///// / //| > | +-----------------------------------+//// / ///| > | |We value your comments, which have |/// / ////| > | |been recorded and automatically |// / /////| > | |emailed back to us for our records.|/ ////////| > +----------------------+-----------------------------------+-----------+ > > sending to informix-list |
| ||||
| The syntax error is because the '::' cast operator is a version 9 specific feature and you are using version 7. But I agree the required conversions should be done implicitly. Not sure, but I suspect the -1213 error is because you have some non-numeric data somewhere in your codigo column and the server has to convert every piece of data in order to know if the rows match or not. If you haven't already, I'd try using a very small test case with just a couple of rows. For instance, this works for me create table foo ( c1 char(30)); insert into foo values ('1'); create table bar ( b1 int); insert into bar values (1); select c1, b1 from foo, bar where foo.c1 = bar.b1; You can add where-clause criteria to select just some rows you know have good data. At least if you get that to work you know that the SQL is ok. You might also try forcing a conversion of the integer column to character. But, even if that works, if I'm right, you are leaving some data behind because there will be some alpha character in "codigo" that will not match the numeric character in "lot". LOL, Chris "victor" <victorvp1@hotmail.com> wrote in message news:<bqmvg2$hd6$2@s1.read.news.oleane.net>... > Hi, > > I have tried, but I have an error 1213. I think I am wrong somewhere. > > Here is my tables : > > Tables textos : > textos type > codigo char(30) > > With codigo = 1, 15,20,34 etc... > > Table Lots : > Lots type > lot integer > > with lots.lot = 1,15,20,34 etc ... > > I need this "request" > select textos.codigo from textos,lots where textos.codigo=lots.lot; > This don't work it is normaly because type is different > > So as you say I try this: select textos.codigo+0 from textos,lots where > textos.codigo=lots.lot > So I have an 1213 error --> A character to numeric conversion process > failed. > > I try : select textos.codigo::INT from textos,lots where > textos.codigo=lots.lot > So I have an 201 error --> Syntaxe error as occurred > > Have you got an explication ?? > > Thanks for your help. > Victor > > "Mark D. Stock" <mdstock@mydassolutions.com> a écrit dans le message de > news:bqb5lt$t7u$1@terabinaries.xmission.com... > > > > victor wrote: > > > > > 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 > > > > Have you tried: > > > > SELECT toto, titi > > FROM table1, table2 > > WHERE table1.titi = table2.toto > > > > The cast should be implicit in any version. Performance may not be > optimum, > > but that's down to your "bad conception". ;-) > > > > To return an INT value, use: > > > > SELECT toto+0, titi > > > > or > > > > SELECT toto::INT, titi > > > > Cheers, > > -- > > Mark. > > > > +----------------------------------------------------------+-----------+ > > | Mark D. Stock mailto:mdstock@MydasSolutions.com |//////// /| > > | Mydas Solutions Ltd http://MydasSolutions.com |///// / //| > > | +-----------------------------------+//// / ///| > > | |We value your comments, which have |/// / ////| > > | |been recorded and automatically |// / /////| > > | |emailed back to us for our records.|/ ////////| > > +----------------------+-----------------------------------+-----------+ > > > > sending to informix-list |