Re: Handling INTERVAL datatypes
Posted in 1997
Here's a compact stored procedure that will convert any intra-day
interval to an integer number of seconds:
create procedure intsec(ivsec interval second(9) to second)
returning integer; define sec char(10);
let sec = ivsec;
return sec;
end procedure;
Here's a test sequence that worked (online 7.21):
create table test (iv interval hour to second);
insert into test values ("1:01:01");
insert into test values ("2:02:02");
insert into test values ("3:03:03");
insert into test values ("4:04:04");
insert into test values ("5:05:05");
select iv,intsec(iv) from test;
drop table test;
Resulting in ...
iv (expression)
1:01:01 3661
2:02:02 7322
3:03:03 10983
4:04:04 14644
5:05:05 18305
Cheers,
----------------------------------------------------------------------
John H. Frantz Power-4gl: Extending Informix-4gl
frantz@centrum.is http://www.rl.is/~john/pow4gl.html
In article <34147014.57188646@news>,
pje@fmsc.com.au (Peter Jessup) wrote:
>
> I have a table that contains a couple of columns defined as INTERVAL
> HOUR TO SECOND. Is there an easy way using SQL to cast this into an
> INTEGER datatype representing the number of seconds in the interval?
>
> Failing that can I retrieve the number of hours, minumtes and seconds
> into separate integers? Any help would be greatly apprectiated.
>
> Peter Jessup
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet