Export (0) Print
Expand All
Expand Minimize

SUM (SQL Server Compact Edition)

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 ) 

ALL

Applies the aggregate function to all values. ALL is the default.

expression

A constant, column, or function and any combination of arithmetic, bitwise, and string operators. The expression argument 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.

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

Expression result Return type

integer category

int

numeric category (p, s)

numeric (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 Products table.

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

This is the result set:

Units Remaining
---------------
101

Community Additions

ADD
Show:
© 2014 Microsoft