A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z  special characters  sybase-tech-blog


Category: ASE: Functions: Aggregate Functions

sum()

The aggregate function sum() computes the sum off all values in a column of a table.

Syntax of the Aggregate Function sum()

    sum( [ all | distinct ] expression )
    

The parameters of the Aggregate Function sum()

all
"all" calculates the sum of all values. "all" is the default setting for the function sum().

distinct
"distinct" ignores duplicate values before summing up "distinct" is an optional parameter.

expression
"expression" usually serves as a placeholder for a column name in the function sum().

Usage of the Aggregate Function sum()

The function sum() can only be used for queries on column names which are declared as numeric datatypes. Queries on other datatypes return error messages. NULL values are ignored in queries with sum(). The function sum() always converts the result of a query on integer data fields into the datatype int. Exception to this is the bigint datatype. sum() returns bigint result sets as bigint datatype. To avoid arithmetic overflow errors, variables, to which the result of sum() is assigned, should be declared accordingly.

Example for the Aggregate Function sum()

Returns the sum of all values in the column column_name of the table table_name.

    select sum(number_of_orders) from table_name
    

See also:

ASE T-SQL - Aggregate Functions,
avg(),
count(*),
count(),
count_big(),
max(),
min().