Function Reference > Functions > MOD
  

MOD

Returns the remainder of a division calculation. For example, MOD(8,5) returns 3.

Syntax

MOD( numeric_value, divisor )
Argument
Required/
Optional
Description
numeric_value
Required
Numeric datatype. The values you want to divide. You can enter any valid expression.
divisor
Required
The numeric value you want to divide by. The divisor cannot be 0.

Return Value

Numeric value of the datatype you pass to the function. The remainder of the numeric value divided by the divisor.
NULL if a value passed to the function is NULL.

Example

The following expression returns the modulus of the values in the PRICE column divided by the values in the QTY column:
MOD( PRICE, QTY )
PRICE
QTY
RETURN VALUE
10.00
2
0
12.00
5
2
9.00
2
1
15.00
3
0
NULL
3
NULL
20.00
NULL
NULL
25.00
0
None. Data Integration writes the row into the error rows file.
The last row (25, 0) produced an error because you cannot divide by 0. To avoid dividing by 0, you can create an expression similar to the following, which returns the modulus of Price divided by Quantity only if the quantity is not 0. If the quantity is 0, the function returns NULL:
MOD( PRICE, IIF( QTY = 0, NULL, QTY ))
PRICE
QTY
RETURN VALUE
10.00
2
0
12.00
5
2
9.00
2
1
15.00
3
0
NULL
3
NULL
20.00
NULL
NULL
25.00
0
NULL
The last row (25, 0) produced a NULL rather than an error because the IIF function replaces NULL with the 0 in the QTY column.