Rules on Arithmetic Operations in SQL Server

Q

What Are Arithmetic Operators in SQL Server Transact-SQL?

✍: FYIcenter.com

A

An arithmetic operator performs an arithmetic operation on two expressions of numeric data types. SQL Server supports 5 arithmetic operators:

  • + (Add): Addition
  • - (Subtract): Subtraction
  • * (Multiply): Multiplication
  • / (Divide): Division
  • % (Modulo): Modulation

There are several rules on arithmetic operations:

  • Arithmetic operations are performed on expressions of numeric data types like INT, NUMERIC, and FLOAT.
  • When arithmetic operations are performed on expressions of the same data types, no data type conversion is needed.
  • When arithmetic operations are performed on expressions of different data types, implicit data type conversion will be performed before the arithmetic operation on the expression with a lower data type rank.
  • Numeric data type ranks are from low to high: TINYINT, SMALLINT, INT, BIGINT, SMALLMONEY, MONEY, DECIMAL, and FLOAT.
  • The data type of the resulting value of an arithmetic operation is the same as the two input expressions.

 

Arithmetic Operations with Different Data Types in SQL Server

What Is an Expression in SQL Server

Numeric Expressions and Functions in SQL Server Transact-SQL

⇑⇑ SQL Server Transact-SQL Tutorials

2017-04-01, 1928🔥, 0💬