Export (0) Print
Expand All


SQL Server 2000

Returns the sum of all the values, or only the DISTINCT values, in the expression. SUM can be used with numeric columns only. Null values are ignored.

SUM ( [ ALL ] expression ) 
Applies the aggregate function to all values. ALL is the default.
Is a constant, column, or function and any combination of arithmetic, bitwise, and string operators. expression is an expression of the exact numeric or approximate numeric data type categories, except for the bit data type. Aggregate functions and subqueries are not permitted.
Return Types

Returns the summation of all expression values in the most precise expression data type.

Expression result Return type
integer category int
decimal category (p, s) decimal(38, s)
money and smallmoney category money
float and real category float


The following example queries for the total number of units in stock for all discontinued products in the Northwind database.

SELECT SUM(UnitsInStock)AS "Units Remaining" FROM Products WHERE Discontinued = 'True'

This is the result set:

Units Remaining

© 2015 Microsoft