title: Better way for Getting Total Count along with Paging in SQL Server 2012
body: <p>I have requirement to get the total count of records along with paging. At present I am doing it as listed below in SQL Server 2012. This needs a separate query for getting count. Is there any improved way in SQL Server 2012?</p>
  
  <pre><code>ALTER PROCEDURE dbo.tpGetPageRecords
  (
      @OffSetRowNo INT,     
      @FetchRowNo INT,
      @TotalCount INT OUT
  ) 
  AS 
  
  SELECT CSTNO, CSTABBR 
  FROM DBATABC
  WHERE CSTABBR LIKE 'A%'
  ORDER BY CSTNO
  OFFSET ( @OffSetRowNo-1 ) * @FetchRowNo ROWS
  FETCH NEXT @FetchRowNo ROWS ONLY
  
  SET @TotalCount = 
  (SELECT COUNT(*)
  FROM DBATABC
  WHERE CSTABBR LIKE 'A%')
  
  
  GO
  </code></pre>