Get Row Count including Column Values in SQL Server

Some time you need to show Total number of records and column value from a SQL Server table.

Below is my Data Table from I am reading records:


Image 1: Reading Record

Now Select Column from this table.


Image 2: Select Column

Now I want to show one more column which will show Total Number of records in this table. So First below thought in our mind come:

  1. SELECT COUNT(*) AS TotalRecords, EMPLOYEE_ID,NAME,EMAIL,MOBILE,  
  2. COUNTRY FROM EMPLOYEETEAM  
If you use avobe query then you will get below error message:


Image 3: Error Messege

So the right Query is
  1. SELECT COUNT(*) OVER (PARTITION BY 1) AS TotalRecords, EMPLOYEE_ID, NAME,  
  2. EMAIL, MOBILE, COUNTRY FROM EMPLOYEETEAM 

Image 4: Output
Ebook Download
View all
Learn
View all