Applies To: SQL Server 2014, SQL Server 2016 Preview
Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).
Returns the remainder of one number divided by another.
Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database, Azure SQL Data Warehouse Public Preview.
A. Simple example
The following example divides the number 38 by 5. This results in 7 as the integer portion of the result, and demonstrates how modulo returns the remainder of 3.
SELECT 38 / 5 AS Integer, 38 % 5 AS Remainder ;
B. Example using columns in a table
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 AdventureWorks2012; GO SELECT TOP(100)ProductID, UnitPrice, OrderQty, CAST((UnitPrice) AS int) % OrderQty AS Modulo FROM Sales.SalesOrderDetail; GO