Export (0) Print
Expand All
Expand Minimize

Returns the number of items in a group.



COUNT ( { [ ALL ] expression | * } ) 

ALL

Applies the aggregate function to all values. ALL is the default.

expression

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.


int

The following example counts the discontinued items in a table.

SELECT COUNT([Product ID]) AS "Total Discontinued" FROM Products WHERE Discontinued = 1

This is the result set:

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

Release

History

5 December 2005

Changed content
  • Updated code example

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft