|
<< Click to Display Table of Contents >> Arithmetic operators |
![]() ![]()
|
Perform arithmetic operations.
numeric_value1 + numeric_value2
numeric_value1 - numeric_value2
numeric_value1 * numeric_value2
numeric_value1 / numeric_value2
Use arithmetic operators to perform arithmetic calculations on data in SELECT queries. Calculations can be performed wherever non-aggregated data values are allowed, such as in a SELECT or WHERE clause. In the statement below, a column value is multiplied by a numeric literal.
SELECT (ItemsTotal * 0.0825) AS Tax
FROM Orders
Arithmetic calculations are performed in the normal order of precedence: multiplication, division, addition, and then subtraction. To cause a calculation to be performed out of the normal order of precedence, use parentheses around the operation to be performed first. In the statement below the addition is performed before the multiplication.
SELECT (N.Numbers * (N.Multiple + 1)) AS Result
FROM Numbertable N
Arithmetic operators operate only on numeric values. To use arithmetic operators on non-numeric values, first use the CAST function to convert the column to a numeric type.