pagination - Better way for Getting Total Count along with Paging in SQL Server 2012 -


i have requirement total count of records along paging. @ present doing listed below in sql server 2012. needs separate query getting count. there improved way in sql server 2012?

alter procedure dbo.tpgetpagerecords (     @offsetrowno int,          @fetchrowno int,     @totalcount int out )    select cstno, cstabbr  dbatabc cstabbr 'a%' order cstno offset ( @offsetrowno-1 ) * @fetchrowno rows fetch next @fetchrowno rows  set @totalcount =  (select count(*) dbatabc cstabbr 'a%')   go 

if we're allowed change contract, can have:

select cstno, cstabbr,count(*) on () totalcount dbatabc cstabbr 'a%' order cstno offset ( @offsetrowno-1 ) * @fetchrowno rows fetch next @fetchrowno rows 

and total available separate column in result set. unfortunately, there's no way assign value variable in same statement, can no longer provide out parameter.

this uses over clause (available since 2005) allow aggregate computed on entire (unlimited) result set , without requiring grouping.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -