SQL Server COUNT() Function
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 |
---|