SQL Server : Arithmetic Operators

Arithmetic Operator :

The arithmetic operators supported by SQL Server are:

  • + for addition
  • - for subtraction
  • / for division
  • * for multiplication
  • % for modulo

The modulo arithmetic operator is used to obtain the remainder of two divisble numeric integer values. It cannot be used with money data type columns.
All the arithmetic operators can be used in the SELECT list with the column names and numeric constants in a combination.

  SELECT title_id, price, price+5, ytd_sales*5 from titles. 

When any arithmetic operation is performed on a NULL value, the result is always NULL because NULL values have no explicitly assigned values. Arithmetic operations can be performed on more than one column at a time. Consider the following query code:
  SELECT Title_id=title_id, sValue=ytd_sales*price from titles 

The above query computers the product of ytd_sales and price from the titles table and displays the output with the use-defined headings.
Some rules regarding the usage of arithmetic operators are :
  • Arithmetic operators can be performed on numeric columns or numeric constants.
  • The modulo (%) operator cannot be used with columns of money, smallmoney, float or real datatypes.

Other Operators List


Post a Comment