Computed Values in the Select List

A select list can contain expressions that are built by applying operators to one or more simple expressions. This allows result sets to contain values that do not exist in the base tables, but are calculated from the values stored in the base tables. These result set columns are called derived columns, and include:

Calculations and computations can be performed with data by using numeric columns or numeric constants in a select list with arithmetic operators, functions, conversions, or nested queries. Arithmetic operators let you add, subtract, multiply, and divide numeric data.

These arithmetic operators are supported.

Symbol Operation
+ Addition
- Subtraction
/ Division
* Multiplication
% Modulo

The arithmetic operators that perform addition, subtraction, division, and multiplication can be used on any numeric column or expression ( int, smallint, tinyint, decimal, numeric, float, real, money, or smallmoney). The modulo operator can only be used on int, smallint, or tinyint columns or expressions.

Arithmetic operations can also be performed on datetime and smalldatetime columns using the date functions or regular addition or subtraction arithmetic operators.

You can use arithmetic operators to perform computations involving one or more columns. The use of constants in arithmetic expressions is optional, as shown in this example:

SELECT ProductID, ProductName,

       UnitPrice * UnitsInStock AS InventoryValue

FROM Northwind.dbo.Products

  

See Also
FROM SELECT
Operators Join Fundamentals
Subquery Fundamentals + (Add)
- (Subtract) Functions

  


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