Re: Informix SQL query on INTEGER column
Posted in 1993
Topics: SQL Development & Query Writing, Stored Procedures & SPL, Migration, Import/Export & Data Conversion
>
> I'm trying to do an informix SQL SELECT on an INTEGER column to get
> only the first 3 digits of the number. For example, if i have
> the following table:
>
> CREATE TABLE t1
> ( field1 INTEGER,
> field2 CHAR(10) );>
> Now, if I have 12345 in field1, how can I do a select on the table
> and only display the first 3 digits (ie: 123).
>
> Any help is appreciated!
>
> TIA,
>
> Greg George
>
You can do something like:
Solution 1:
create temp table t11 (field1 char(10),field1 char(10));
insert into t11
select field1,field1 from t1;
select fld1[1,3],fld2 from t11;
Solution 2:
Or if you are running Version 5.0 and greater then:
Create a stored procedure like:
create procedure disp_3(in_int integer)
returning char(3); define int_char char(10);
let int_char = in_int;
return int_char[1,3];
end procedure;
and do a select like:
---------------------
select disp_3(field1),field2 from t1
+--------------------------+---------------------------+
| G.T.Madavan, | e-mail: gtmad@smi.mn.org |
| Systems Migration Inc., | Phone : (612) 890-0040 |
| Burnsville, MN, U.S.A | Fax : (612) 890-0966 |
+--------------------------+---------------------------+