Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Operator RSS Feeds

Examples of % ( Modulo ) Operator

Posted By: Sarita Patel     Category: SQL Server     Views: 19857

This article describes %( Modulo ) operator with different examples.

Modulo operator provides the remainder of one number divided by another number.

Syntax of % ( Modulo ) Operators : 

dividend % divisor

Dividend is the numeric expression to divide. Dividend must be any expression of integer data type in sql server.

Divisor is the numeric expression to divide the dividend. Divisor must be expression of integer data type except in sql server. 



Example of  % ( Modulo ) Operator :

Example 1 : Displays use of modulo for numeric numbers.

SELECT 15%2

Output
1

Above example explains how can we use modulo operator to get remainder of numeric numbers.




Example 2 : Example of performing modulo operation on table field UnitPrice.

SELECT ProductName, UnitPrice % 4  AS Price
FROM Products

Output
ProductName                               Price
Chai  2.00
Chang  3.00
Aniseed Syrup  1.35
Chef Anton's Cajun Seasoning  1.00
Chef Anton's Gumbo Mix  2.70

Above example displays how can we perform modulo operation on table field UnitPrice by numeric value.




Example 3 : Example of modulo operator between 2 fields of tables. 

SELECT ProductName, UnitPrice % Discount AS Remainder
FROM Products

Output
ProductName                            Remaindert
Chai  3
Chang  5
Aniseed Syrup  2
Chef Anton's Cajun Seasoning  4
Chef Anton's Gumbo Mix  8

Above example displays remainder by performing % operation between UnitPrice and Discount table fields. 
  
Share: 


Didn't find what you were looking for? Find more on Examples of % ( Modulo ) Operator Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of Examples of % ( Modulo ) Operator is from United States.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!