Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
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 ) 


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


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


numeric category (p, s)

numeric (38, s)

money and smallmoney category


float and real category


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

Community Additions

© 2015 Microsoft