% (Modulo) (TSQL Operator)

Returns the remainder of one number divided by another.

Syntax

expression % expression

Arguments

expression
is a numeric expression of type tinyint, smallint, int, bigint.

Return Types

Returns the datatype of the expression with the highest type precedence.

Remarks

If second operand is 0, an error is raised.

Examples

PRINT 123 % 50;

-- varchar is converted to int, because int has highest type precedence
PRINT '123' % 50;

The result is:

23
23

Example modulo by 0

PRINT 123 % 0;

The result is:

<Arithmetic error. INT modulo by 0.>
RSQL, a simple alternative to Microsoft SQL Server