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.
Syntax
SUM ( [ ALL ] expression )
Arguments
- 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.
Return Value
Returns the summation of all expressionvalues in the most precise expressiondata 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 |
Code Example
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