Subject Re: [firebird-support] MOD without UDF
Author Markus Ostenried
At 17:23 Wednesday, 08.12.2004 +0100, Arn wrote:
>I need to perform a MOD operation in a procedure.
>
>Some time ago Ali Goken (Sp.?) ( Hi Ali) put in this list a way to do
>MOD without using UDF.
>
>Someone can recall this formula???
>Or know an equivalent one??


Hi,

try this:

CREATE PROCEDURE PROC_MODULUS( DIVIDEND INTEGER
, DIVISOR INTEGER )
RETURNS ( RESULT INTEGER )
AS
BEGIN
/* This procedure calculates the modulus of two numbers */
IF (Dividend = 0) THEN
Result = 0;
ELSE
Result = Dividend-(CAST((Dividend / Divisor)-0.49 AS INTEGER)*Divisor);
END

HTH,
Markus