Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

% (Modulus) (Transact-SQL)

Applies to: 👁 Image
SQL Server 👁 Image
Azure SQL Database 👁 Image
Azure SQL Managed Instance 👁 Image
Azure Synapse Analytics 👁 Image
Analytics Platform System (PDW) 👁 Image
SQL analytics endpoint in Microsoft Fabric 👁 Image
Warehouse in Microsoft Fabric 👁 Image
SQL database in Microsoft Fabric

Returns the remainder of one number divided by another.

👁 Image
Transact-SQL syntax conventions

Syntax

dividend % divisor

Arguments

dividend

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

The numeric expression by which to divide the dividend. 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.

Result types

Determined by data types of the two arguments.

Remarks

You can use the modulo arithmetic operator 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.

Examples

The code samples in this article use the AdventureWorks2025 or AdventureWorksDW2025 sample database, which you can download from the Microsoft SQL Server Samples and Community Projects home page.

A. Basic example

The following example divides the number 38 by 5. The result is 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.

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

Examples: Azure Synapse Analytics and Analytics Platform System (PDW)

C: Basic example

The following example shows results for the % operator when dividing 3 by 2.

SELECT TOP(1) 3 % 2
FROM DimEmployee;

Here's the result set.

1

Related content


Feedback

Was this page helpful?

Additional resources