Arithmetic Operators

Arithmetic operators can be used for any arithmetic computations, such as:

Here is some information about arithmetic operators:

The following SELECT statement subtracts the part of the year-to-date sales that the author receives (sales * author’s royalty percentage / 100) from the total sales. The result is the amount of money the publisher receives. The product of ytd_sales and royalty is calculated first because the operator is multiplication. Next, the total is divided by 100. Then this result is subtracted from ytd_sales.

USE pubs

SELECT title_id, ytd_sales - ytd_sales * royalty / 100

FROM titles

  

For clarity, you can use parentheses:

USE pubs

SELECT title_id, ytd_sales - ((ytd_sales * royalty) / 100)

FROM titles

  

You can also use parentheses to change the order of execution. Calculations inside parentheses are evaluated first. If parentheses are nested, the most deeply nested calculation has precedence. For example, the result and meaning of the preceding query can be changed if you use parentheses to force the evaluation of subtraction before multiplication:

USE pubs

SELECT title_id, (ytd_sales - ytd_sales) * royalty / 100

FROM titles

  

See Also
- (Subtract) + (Add)
* (Multiply) / (Divide)

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.