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
Collapse the table of content
Expand the table of content
Expand Minimize

SUM (SQL Server Compact)

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 expressionvalues in the most precise expressiondata 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([Units In Stock])AS "Units Remaining" FROM Products WHERE Discontinued = 'True'

This is the result set:

Units Remaining
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft