Getting a Subset of Records along with Total Record Count

后端 未结 2 1465
长情又很酷
长情又很酷 2021-02-09 21:38

I\'m working on returning a recordset from SQL Server 2008 to do some pagination. I\'m only returning 15 records at a time, but I need to have the total number of matches along

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-09 21:54

    I've handled a situation a bit similar to this in the past by not bothering to determine a definite row count, but using the query plan to give me an estimated row count, a bit like the first item in this link describes:

    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=108658

    The intention was then to deliver whatever rows have been asked for within the range (from say 900-915) and then returning the estimated row count, like

    rows 900-915 of approx. 990
    

    which avoided having to count all rows. Once the user moves beyond that point, I just showed

    rows 1000-1015 of approx. 1015
    

    i.e. just taking the last requested row as my new estimate.

提交回复
热议问题