THE WORLD'S LARGEST WEB DEVELOPER SITE

SQL Server COUNT() Function

❮ SQL Server Functions

Example

Return the number of products in the "Products" table:

SELECT COUNT(ProductID) AS NumberOfProducts FROM Products;
Try it Yourself »

Definition and Usage

The COUNT() function returns the number of records in a select query (counts only NOT NULL values).

Syntax

COUNT(expression)

Note: If a record in the expression contains a NULL value, it is not included in the COUNT() calculation.

Parameter Values

Parameter Description
expression Required. A field or a string value

Technical Details

Works in: SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

❮ SQL Server Functions