Subject Re: [firebird-support] Maths problem 1.0(Dialect 1) -> 1.5(Dialect 3)
Author Helen Borrie
At 03:30 PM 1/09/2003 +0100, you wrote:
>OK what am I doing wrong?
>
>(('NOW' - OLD.LAST) * 1440)
>
>Is working fine in FB1.0 on a Dialect 1 database
>(LAST is a TIMESTAMP, and the value goes into a SMALLINT)
>
>CAST((CAST('NOW' AS TIMESTAMP) - OLD.LAST) AS INTEGER)* 1440
>
>Will actually compile on FB1.5RC4 on a Dialect 3 database,
>but it is not putting 'minutes' into the SMALLINT - I always
>get 0.
>
>This equation is used in several 'INSERT' triggers and all
>give the same problem.

The integer casting will truncate the result, not round it, so don't do the
casting to integer until you've done the multiplication on the DOUBLE
PRECISION.

Try
CAST (CURRENT_DATE - OLD.LAST) * 1440) AS INTEGER

btw, If you need "nearest minute" rather than "last whole minute", don't
cast the double, but pass it to a ROUND(..) udf.

--h