SQL Server Count() functions could be used as sql count command to count aggregate values.
Count () function has optional argument and expression. To find the general count of values we could use different forms count or supply different argument as described below and it will return the same value.
USE AdventureWorks; GO --COUNT ALL FirstName SELECT count(ALL FirstName ) AS CountOfPerson FROM Person.Person; --COUNT FirstName SELECT count(FirstName ) AS CountOfPerson FROM Person.Person; --COUNT * SELECT count(* ) AS CountOfPerson FROM Person.Person; GO |
We may also need to query a distinct FirstName values in our table and to do that we could use a DISTINCT argument inside the Count() function.
--COUNT DISTINCT FirstName SELECT count(DISTINCT FirstName ) AS CountOfPerson FROM Person.Person; |
Read more:
http://technet.microsoft.com/en-us/library/ms175997.aspx