Aggregate Functions (SqlClient for Entity Framework)

 

The .NET Framework Data Provider for SQL Server (SqlClient) provides aggregate functions. Aggregate functions perform calculations on a set of input values and return a value. These functions are in the SqlServer namespace, which is available when you use SqlClient. A provider's namespace property allows the Entity Framework to discover which prefix is used by this provider for specific constructs, such as types and functions.

The following table shows the SqlClient aggregate functions.

FunctionDescription
AVG( expression )Returns the average of the values in a collection.

Null values are ignored.

 Arguments

An Int32, Int64, Double, and Decimal.

 Return Value

The type of expression.

 Example

[!CODE [DP EntityServices Concepts#SQLSERVER_AVG](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#sqlserver_avg)]
CHECKSUM_AGG( collection )Returns the checksum of the values in a collection.

Null values are ignored.

 Arguments

A Collection (Int32).

 Return Value

An Int32.

 Example

[!CODE [DP EntityServices Concepts#SQLSERVER_CHECKSUM](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#sqlserver_checksum)]
COUNT( expression )Returns the number of items in a collection as an Int32.

 Arguments

A Collection (T) where T is one of the following types:

 Guid (not returned in SQL Server 2000),

 Boolean, Double, DateTime, DateTimeOffset, Time, String, or Binary.

 Return Value

An Int32.

 Example

[!CODE [DP EntityServices Concepts#SQLSERVER_COUNT](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#sqlserver_count)]
COUNT_BIG( expression )Returns the number of items in a collection as a bigint.

 Arguments

A Collection (T) where T is one of the following types:

 Guid (not returned in SQL Server 2000), Boolean, Double, DateTime, DateTimeOffset, Time, String, or Binary.

 Return Value

An Int64.

 Example

[!CODE [DP EntityServices Concepts#SQLSERVER_COUNTBIG](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#sqlserver_countbig)]
MAX( expression )Returns the maximum value the collection.

 Arguments

A Collection (T) where T is one of the following types: Byte, Int16, Int32, Int64, Byte, Single, Double, Decimal, DateTime, DateTimeOffset, Time, String, Binary.

 Return Value

The type of expression.

 Example

[!CODE [DP EntityServices Concepts#SQLSERVER_MAX](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#sqlserver_max)]
MIN( expression )Returns the minimum value in a collection.

 Arguments

A Collection (T) where T is one of the following types: Byte, Int16, Int32, Int64, Byte, Single, Double, Decimal, DateTime, DateTimeOffset, Time, String,

 Binary.

 Return Value

The type of expression.

 Example

[!CODE [DP EntityServices Concepts#SQLSERVER_MIN](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#sqlserver_min)]
STDEV( expression )Returns the statistical standard deviation of all values in the specified expression.

 Arguments

A Collection (Double).

 Return Value

A Double.

 Example

[!CODE [DP EntityServices Concepts#SQLSERVER_STDEV](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#sqlserver_stdev)]
STDEVP( expression )Returns the statistical standard deviation for the population for all values in the specified expression.

 Arguments

A Collection (Double).

 Return Value

A Double.

 Example

[!CODE [DP EntityServices Concepts#SQLSERVER_STDEVP](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#sqlserver_stdevp)]
SUM( expression )Returns the sum of all the values in the collection.

 Arguments

A Collection (T) where T is one of the following types: Int32, Int64, Double, Decimal.

 Return Value

The type of expression.

 Example

[!CODE [DP EntityServices Concepts#SQLSERVER_SUM](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#sqlserver_sum)]
VAR( expression )Returns the statistical variance of all values in the specified expression.

 Arguments

A Collection (Double).

 Return Value

A Double.

 Example

[!CODE [DP EntityServices Concepts#SQLSERVER_VAR](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#sqlserver_var)]
VARP( expression )Returns the statistical variance for the population for all values in the specified expression.

 Arguments

A Collection (Double).

 Return Value

A Double.

 Example

[!CODE [DP EntityServices Concepts#SQLSERVER_VARP](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#sqlserver_varp)]

For more information about the aggregate functions that SqlClient supports, see the documentation for the SQL Server version that you specified in the SqlClient provider manifest:

SQL Server 2000SQL Server 2005SQL Server 2008
Aggregate Functions (Transact-SQL)Aggregate Functions (Transact-SQL)Aggregate Functions (Transact-SQL)

Entity SQL Language
Aggregate Canonical Functions

Show: