Share via


% (Modulo) (Transact-SQL)

Returns the remainder of one number divided by another.

Topic link iconTransact-SQL Syntax Conventions

Syntax

dividend % divisor

Arguments

  • dividend
    Is the numeric expression to divide. dividend must be a valid expression of any one of the data types in the integer and monetary data type categories, or the numeric data type.
  • divisor
    Is the numeric expression to divide the dividend by. divisor must be any valid expression of any one of the data types in the integer and monetary data type categories, or the numeric data type.

Remarks

The modulo arithmetic operator can be used in the select list of the SELECT statement with any combination of column names, numeric constants, or any valid expression of the integer and monetary data type categories or the numeric data type.

Result Types

Determined by data types of the two arguments.

Examples

The following example returns the product ID number, the unit price of the product, and the modulo (remainder) of dividing the price of each product, converted to an integer value, into the number of products ordered.

USE AdventureWorks;
GO
SELECT TOP(100)ProductID, UnitPrice, OrderQty,
   CAST((UnitPrice) AS int) % OrderQty AS Modulo
FROM Sales.SalesOrderDetail;
GO

See Also

Reference

Functions (Transact-SQL)
LIKE (Transact-SQL)
Operators (Transact-SQL)
SELECT (Transact-SQL)

Help and Information

Getting SQL Server 2005 Assistance