Thursday, April 13, 2017

COUNT() in SQL Server


SQL COUNT() function is used to return the count of values in a column. The COUNT() can only be applied on ANY type column. The COUNT() determines the occurrence of all the non-NULL values in the columns, NULL values are ignored.

Syntax:

     
            SELECT COUNT(ALL | DISTINCT column_name) FROM table_name


column_name is the name of the column of which total occurrences is to be calculated.

table_name is the name of the table


Example 1:
COUNT() on column which does not have any NULL value.

SELECT * FROM TempEmployeePayHistory



SELECT COUNT(Rate) FROM TempEmployeePayHistory



Example 2:
COUNT() on column having NULL values.

          SELECT * FROM TempEmployeePayHistory



SELECT COUNT(Rate) FROM TempEmployeePayHistory



Share This
Previous Post
Next Post

TekGrabs, established in 2017, is in the business of sharing Information. It provides news, articles and photos about the different technologies, inventions in different domains. Provides information on programming and databases.

0 comments: