Informix SQL query on INTEGER column
Posted in 1993
Topics: SQL Development & Query Writing, Stored Procedures & SPL
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
On 29 Jul 1993, Greg George wrote:
> 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
------------------------------------------------------------------------
The solution to this is in the SQL book.
SELECT field1 FROM t1 WHERE field1[1,3] = 123 **(Quotes if text)
where 1 is starting position and 3 is ending location (inclusive).
Regards,
Peter
+---------------------------+--------------------------------------------+
| Peter Estabrook | Internet: estabroo@sea07s.navsea.navy.mil |
| User Technology Assoc. | Voice: (703) 486-7190 |
| 2121 Crystal Drive #103 | Fax : (703) 486-7179 |
| Arlington, VA 22202 USA | Host : Sequent S2000/200 ptx V1.4 |
+---------------------------+--------------------------------------------+
On Mon, 2 Aug 1993, Peter Estabrook wrote: } On 29 Jul 1993, Greg George wrote: } } > 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 } ------------------------------------------------------------------------ } The solution to this is in the SQL book. } } SELECT field1 FROM t1 WHERE field1[1,3] = 123 **(Quotes if text) } } where 1 is starting position and 3 is ending location (inclusive). } } } Regards, } Peter } +---------------------------+--------------------------------------------+ } | Peter Estabrook | Internet: estabroo@sea07s.navsea.navy.mil | } | User Technology Assoc. | Voice: (703) 486-7190 | } | 2121 Crystal Drive #103 | Fax : (703) 486-7179 | } | Arlington, VA 22202 USA | Host : Sequent S2000/200 ptx V1.4 | } +---------------------------+--------------------------------------------+ } I'm sorry this will not work on an integer column (but you knew that). I'm not saying I'm wrong. I thought I was wrong once, but I was mistaken. Peter +---------------------------+--------------------------------------------+ | Peter Estabrook | Internet: estabroo@sea07s.navsea.navy.mil | | User Technology Assoc. | Voice: (703) 486-7190 | | 2121 Crystal Drive #103 | Fax : (703) 486-7179 | | Arlington, VA 22202 USA | Host : Sequent S2000/200 ptx V1.4 | +---------------------------+--------------------------------------------+