Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
VBA Arithmetic Operators in Excel
Next article icon

Arithmetic Operators in SQL Server

Last Updated : 29 Apr, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Arithmetic operators play a crucial role in performing mathematical calculations within SQL Server. These operators allow you to perform addition, subtraction, multiplication, division, and more on numeric data stored in your database tables. In this article, we'll explore the various arithmetic operators available in SQL Server, discuss their usage with examples, and provide outputs to illustrate their functionality, all explained in an easy-to-understand manner for beginners.

Arithmetic Operators in SQL Server

Arithmetic operators in SQL Server are symbols or keywords used to perform mathematical operations such as addition, subtraction, multiplication, division, and modulo (remainder) on numeric data types. These operators can be applied to columns, constants, or expressions in SQL queries to perform calculations and generate desired results.

Common Arithmetic Operators in SQL Server

SQL Server supports the following arithmetic operators:

  • Addition (+): Adds two numeric values together.
  • Subtraction (-): Subtracts one numeric value from another.
  • Multiplication (*): Multiplies two numeric values together.
  • Division (/): Divides one numeric value by another.
  • Modulo (%): Returns the remainder of a division operation.

Addition Operator (+)

The addition operator (+) in SQL Server is used to perform arithmetic addition on numeric values. It adds two numbers together and returns the result as a numeric value.

Syntax:

SELECT number1 + number2 AS result;

Example:

SELECT 5 + 3 AS Result;

Output:

8

In this example, the addition operator calculates the sum of 5 and 3, resulting in 8.

Subtraction Operator (-)

The subtraction operator (-) in SQL Server is used to perform arithmetic subtraction on numeric values. It subtracts one number from another and returns the result as a numeric value.

Syntax:

SELECT number1 - number2 AS result;

Example:

SELECT 10 - 5 AS Result;

Output:

5

In this example, the subtraction operator calculates the difference between 10 and 5, resulting in 5.

Multiplication Operator (*)

The multiplication operator (*) in SQL Server is used to perform arithmetic multiplication on numeric values. It multiplies two numbers together and returns the result as a numeric value.

Syntax:

SELECT number1 * number2 AS result;

Example:

SELECT 4 * 3 AS Result;

Output:

12

In this example, the multiplication operator calculates the product of 4 and 3, resulting in 12.

Division Operator (/)

The division operator (/) in SQL Server is used to perform arithmetic division on numeric values. It divides one number by another and returns the result as a numeric value.

Syntax:

SELECT number1 / number2 AS result;

Example:

SELECT 10 / 2 AS Result;

Output:

5

In this example, the division operator calculates the quotient of dividing 10 by 2, resulting in 5.

Modulus Operator (%)

The modulus operator (%) in SQL Server is used to calculate the remainder of a division operation between two numbers. It returns the remainder after dividing the first number by the second number.

Syntax:

SELECT number1 % number2 AS result;

Example:

SELECT 10 % 3 AS Result;

Output:

1

In this example, the modulus operator calculates the remainder when 10 is divided by 3, resulting in 1.

Order of Precedence

In SQL Server, arithmetic operators follow the standard order of precedence, where multiplication and division take precedence over addition and subtraction. You can use parentheses to control the order of operations.

Example:

SELECT 5 + 3 * 2 AS Result;

Output:

11

In the above example, multiplication is performed first, resulting in 3 * 2 = 6, then addition is performed, resulting in 5 + 6 = 11.

Combining Arithmetic Operators

You can combine multiple arithmetic operators in a single expression to perform complex calculations.

Example:

SELECT (10 + 5) * 2 / 3 AS Result;

Output:

10

In the above example, addition (10 + 5) is performed first, resulting in 15. Then, multiplication (15 * 2) is performed, resulting in 30. Finally, division (30 / 3) is performed, resulting in 10.

Handling NULL Values

When performing arithmetic operations involving NULL values, the result is NULL unless handled explicitly using the ISNULL or COALESCE functions.

Example:

SELECT ISNULL(10, 0) / ISNULL(NULL, 1) AS Result;

Output:

10

In the above example, ISNULL is used to replace the NULL value with 0 before division, resulting in 10.

Conclusion

Arithmetic operators are fundamental in SQL Server for performing mathematical calculations on numeric data. By understanding and utilizing these operators, you can manipulate data effectively within your database queries. In this article, we discussed addition, subtraction, multiplication, division, and modulus operators, along with their usage examples and outputs.

Additionally, we explored the order of precedence and handling NULL values in arithmetic operations. As you continue to work with SQL Server, mastering arithmetic operators will enable you to perform a wide range of calculations and analyses on your data. Experiment with these concepts in your SQL queries to deepen your understanding and enhance your SQL skills.


Next Article
VBA Arithmetic Operators in Excel

A

abhisheksi7gbu
Improve
Article Tags :
  • SQL Server
  • Databases

Similar Reads

  • SQL Server Arithmetic Operators
    Microsoft's SQL Server, a capable relational database management system, has a lot of features to deal with data and make manipulations purely. SQL Server, in addition to the many features available to users, has a set of operators for arithmetic which allows users of databases to perform mathematic
    3 min read
  • Arithmetic Operators in PostgreSQL
    PostgreSQL is an advanced relational database system that supports both relational (SQL) and non-relational (JSON) queries. It is free and open-source. One of the most fundamental properties of database systems is arithmetical operations, without which a multitude of tasks, from simple arithmetic to
    8 min read
  • Arithmetic Operators in Solidity
    Arithmetic operators are used to perform arithmetic or mathematical operations. Solidity has the following types of arithmetic operators: Addition: The addition operator takes two operands and results in a sum of these operands. It is denoted by +.Subtraction: The subtraction operator takes two oper
    2 min read
  • VBA Arithmetic Operators in Excel
    Arithmetic Operators are the operators which perform mathematical operation or which perform any operation between two numbers like addition(+), subtraction(-), multiplication(*), division( / ), exponentiation(^), modulus(Mod), Bit-Shift operations. In this article, we will learn about the excel VBA
    3 min read
  • Arithmetic Operators in LISP
    Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, and division. There are 7 arithmetic operators in LISP that are listed in the below table: OperatorSyntaxDescriptionAddition Operator(+)+ num1 num2Add the two numbersSubtraction Operator(-)-
    2 min read
  • Bash Script - Arithmetic Operators
    In this article, we will see arithmetic operators in bash script. Arithmetic operators is used to perform arithmetic operations. Bash script supports 11 arithmetic operators. All the operators with their uses is given below: OperatorNameUseExample+AdditionIt adds two operandsresult= a+b-SubtractionI
    3 min read
  • Arithmetic Operations
    Arithmetic Operations are the basic mathematical operations—Addition, Subtraction, Multiplication, and Division—used for calculations. These operations form the foundation of mathematics and are essential in daily life, such as sharing items, calculating bills, solving time and work problems, and in
    10 min read
  • Relational Operators in SQL Server
    In SQL Server, relational operators are used to compare values and establish relationships between data stored in tables. These operators allow us to perform logical comparisons to filter data based on specific conditions. Understanding relational operators is fundamental for querying and manipulati
    4 min read
  • What are the Properties of Operations in Arithmetic?
    Arithmetic probably has the longest history during the time. It is a method of calculation that is been in use from ancient times for normal calculations like measurements, labeling, and all sorts of day-to-day calculations to obtain definite values. The term got originated from the Greek word "arit
    6 min read
  • Real Life Applications of Arithmetic Operations
    Arithmetic operations are basic calculations you do with numbers. They include addition (combining numbers), subtraction (taking one number away from another), multiplication (repeated addition), and division (sharing or grouping numbers). Arithmetic operations are core foundation of mathematics. In
    8 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences