Subject | Re: [firebird-support] Value check that I don't now how to solve |
---|---|
Author | Markus Ostenried |
Post date | 2003-11-30T15:23:05Z |
At 16:48 Sunday, 30.11.2003 +0100, you wrote:
I once found this useful stored procedure:
<code>
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
</code>
HTH,
Markus
>I woul'd do it with a trigger (befor insert, befor edit) and the UDF MOD:for the integer operation modulus you don't need an udf.
>IF NUMBER * 100 MOD 25 <> 0 -> raise an exception
I once found this useful stored procedure:
<code>
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
</code>
HTH,
Markus