cancel
Showing results for 
Search instead for 
Did you mean: 

stored procedure return result set and total row count

Former Member
8,111

Hi I would like to implement "infinite scroll" in a web client library called ExtJS.(The backend is SQLA,JAVA,DBUtils,REST,JSON)

This means each DB fetch only returns a fraction of the list from the DB defined by parameters Start and Limit. This divides the list into "pages" (of size Limit) and only "visible" pages are fetched.

ExtJS also wants to know the total size of the list. How do I go about returning a "page" of rows plus a scalar that is the total size of the list, using a stored procedure

Or am I forced to call 2 stored procedures?

Peter

Accepted Solutions (0)

Answers (2)

Answers (2)

JimDiaz
Participant

If you don't mind the total count returned with each row you can use select top x start at y column names, COUNT(*) OVER() AS TotalRows from tablename order by xyz

fvestjens
Participant
0 Kudos

It would be nice if we could have a similar setup for json as we have for XML:

select
   (select count() from address) as NumberOfRecords,
   (select Id, Code from address order by Id for xml auto,elements) as Address
for xml auto, elements


If we could replace XML with JSON then you would get what you need. Maybe something for the future?

I tried to achieve something like this with a work around but I couldn't succeed.