Using Count with All keyword in SQL Server 2008

In this article I describe how to use Count with All keyword in SQL
  • 2552

Introduction

Count is one of the aggregate function in SQL Server 2008 and used to count the number of rows in a database table. Aggregate functions include avg, max, min, count and sum functions. Count can be used with two keyword, one is ALL and another is DISTINCT. Count with ALL keyword is used to return number of all rows in a database table. Count function does not count the null values from the column.

Example:

Return number of distinct rows from table

SELECT [ID]
,[F_Name]
,[L_Name]
,[Salary]
,[Region]
,[City]
FROM [deep].[dbo].[Employee]
GO
select COUNT(All F_Name)as TotalEmployee from Employee

Output:

Count(All)Function-in-sql.jpg


Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.