Export (0) Print
Expand All

COUNT

SQL Server 2000

Returns the number of items in a group.

Syntax
COUNT ( { [ ALL ] expression | * } ) 
Arguments
ALL
Applies the aggregate function to all values. ALL is the default.
expression
Is an expression of any type except uniqueidentifier, image, or ntext. Aggregate functions and subqueries are not permitted.
*
Specifies that all rows should be counted to return the total number of rows in a table. COUNT(*) takes no parameters. COUNT(*) does not require an expression parameter because, by definition, it does not use information about any particular column. COUNT(*) returns the number of rows in a specified table without eliminating duplicates. It counts each row separately, including rows that contain null values.
Return Types

int

Examples

The following example counts the discontinued items in the Products table in the Northwind database.

SELECT COUNT(ProductID) AS "Total Discontinued" FROM Products WHERE Discontinued = 1

This is the result set:

Total Discontinued
--------------------
8

Show:
© 2014 Microsoft