如何返回包含所有行和所有行数的对象
我有一个根据页码返回 20 行的存储过程:
CREATE PROCEDURE SP_GET_ALL
@PAGE INT
AS
SELECT *
FROM Item
ORDER BY ID
OFFSET (@PAGE - 1) * 20 ROWS
FETCH NEXT 20 ROWS ONLY
当我使用 API
时,结果如下所示,
[
{id:1, name:"name1"},
{id:2, name:"name2"},
{id:3, name:"name3"},
{id:4, name:"name4"},
{id:5, name:"name5"},
{id:6, name:"name6"},
{id:7, name:"name7"},
....
]
我想返回同一查询中所有行的总数以设置网页分页。例如,
{
count: 1000,
rows:[
{id:1, name:"name1"},
{id:2, name:"name2"},
{id:3, name:"name3"},
{id:4, name:"name4"},
{id:5, name:"name5"},
{id:6, name:"name6"},
{id:7, name:"name7"},
....
]
}
我不想执行两个请求来获取行和所有行的总数。
I have a stored procedure that returns 20 rows based on page number:
CREATE PROCEDURE SP_GET_ALL
@PAGE INT
AS
SELECT *
FROM Item
ORDER BY ID
OFFSET (@PAGE - 1) * 20 ROWS
FETCH NEXT 20 ROWS ONLY
When I consume the API
the result is like this
[
{id:1, name:"name1"},
{id:2, name:"name2"},
{id:3, name:"name3"},
{id:4, name:"name4"},
{id:5, name:"name5"},
{id:6, name:"name6"},
{id:7, name:"name7"},
....
]
I want to return the total count of all rows in the same query to set up web pagination. for example
{
count: 1000,
rows:[
{id:1, name:"name1"},
{id:2, name:"name2"},
{id:3, name:"name3"},
{id:4, name:"name4"},
{id:5, name:"name5"},
{id:6, name:"name6"},
{id:7, name:"name7"},
....
]
}
I don't want to do two requests to get the rows and the total count of all the rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论