Re: Number of hours from interval, how?
Posted in 1997
Topics: Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL
Hi all,
thank you for your help, especially the following:
Jonathan Leffler wrote:
>
[Snip]
>
> I think an SP should work if done correctly:
>
> CREATE PROCEDURE hours_between(d1 DATETIME YEAR TO HOUR, d2 DATETIME YEAR TO HOUR)
> RETURNING INTERVAL HOUR(9) TO HOUR;> DEFINE n INTERVAL HOUR(9) TO HOUR;
> LET n = d1 - d2;
> RETURN n;
> END PROCEDURE;
>
> SELECT CURRENT YEAR TO HOUR,
> hours_between(CURRENT YEAR TO HOUR, DATETIME(1997-01-01 00) YEAR TO HOUR)
> FROM SysTables
> WHERE tabid = 1;
>
> 1997-05-21 17 3377
>
[Snip - lot of useful ESQL-C Code saved in my archive]
Yes that did it. In my tries I overlooked the possibility of supplying
the width of the result. The (9) in HOUR(9) is essential here.
I slightly modified this to return an integer value, as suggested.
It then looks like this:
CREATE PROCEDURE hours_between(d1 DATETIME YEAR TO HOUR,
d2 DATETIME YEAR TO HOUR)
RETURNING INTEGER; DEFINE n INTERVAL HOUR(9) TO HOUR;
DEFINE s CHAR(10);
DEFINE the_result INTEGER;
LET n = d1 - d2;
LET s = n;
LET the_result = s;
RETURN the_result;
END PROCEDURE;
A direct conversion from interval to integer is not possible I think,
something like
LET the_result = n;
didn't work.
Thanks again.
Gottfried.
-----.....-----.....-----.....-----.....-----.....-----.....-----.....-----
/ Quantum Gesellschaft f'r
Software
___Gottfried Schwieters___ Emil-Figge-Stra'e
83
/ 44227 Dortmund,
Germany