如何在不使用OFFSET MSSQL服务器的情况下在存储过程中使用分页?
如何在不使用OFFSET MSSQL服务器的情况下在存储过程中使用分页?
我想在 asp .net Web 应用程序 (MVC) 中实现像 Google 一样的分页
ALTER PROCEDURE BooksGetList
@BookName VARCHAR(50) = null, @BookPublisherId INT = null, @BookCategoryId INT = null
AS BEGIN
SELECT
ISNULL([Books].[BookId], '') AS [BookId],
ISNULL([Books].[BookName], '') AS [BookName],
ISNULL([BookCategories].[BookCategoryId], '') AS [BookCategoryId],
ISNULL([BookCategories].[BookCategoryName], '') AS [BookCategoryName],
ISNULL([BookPublishers].[BookPublisherId], '') AS [BookPublisherId],
ISNULL([BookPublishers].[BookPublisherName], '') AS [BookPublisherName],
ISNULL([Books].[BookQuantity], '') AS [BookQuantity],
ISNULL([Books].[IsActive], '') AS [IsActive]
FROM
[Books] Inner Join BookCategories On [BookCategories].BookCategoryId = [Books].BookCategoryId
Inner Join BookPublishers On [BookPublishers].BookPublisherId = [Books].BookPublisherId
Where
([Books].[BookName] LIKE '%'+@BookName+'%' OR @BookName IS NULL)
AND ([BookCategories].BookCategoryId = @BookCategoryId OR @BookCategoryId IS NULL)
AND ([BookPublishers].BookPublisherId = @BookPublisherId OR @BookPublisherId IS NULL)
ORDER BY BookId
END
GO
How to use Pagination in stored procedure without using OFFSET MSSQL server?
I want to implement paging Like Google in a asp .net web application (MVC)
ALTER PROCEDURE BooksGetList
@BookName VARCHAR(50) = null, @BookPublisherId INT = null, @BookCategoryId INT = null
AS BEGIN
SELECT
ISNULL([Books].[BookId], '') AS [BookId],
ISNULL([Books].[BookName], '') AS [BookName],
ISNULL([BookCategories].[BookCategoryId], '') AS [BookCategoryId],
ISNULL([BookCategories].[BookCategoryName], '') AS [BookCategoryName],
ISNULL([BookPublishers].[BookPublisherId], '') AS [BookPublisherId],
ISNULL([BookPublishers].[BookPublisherName], '') AS [BookPublisherName],
ISNULL([Books].[BookQuantity], '') AS [BookQuantity],
ISNULL([Books].[IsActive], '') AS [IsActive]
FROM
[Books] Inner Join BookCategories On [BookCategories].BookCategoryId = [Books].BookCategoryId
Inner Join BookPublishers On [BookPublishers].BookPublisherId = [Books].BookPublisherId
Where
([Books].[BookName] LIKE '%'+@BookName+'%' OR @BookName IS NULL)
AND ([BookCategories].BookCategoryId = @BookCategoryId OR @BookCategoryId IS NULL)
AND ([BookPublishers].BookPublisherId = @BookPublisherId OR @BookPublisherId IS NULL)
ORDER BY BookId
END
GO
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 2008 R2 或更早版本,则无法使用 OFFSET FETCH,
您可以选择使用
ROW_NUMBER()
并重写您的查询,例如:使用 OFFSET
此查询不使用 OFFSET 使用
ROW_NUMBER()
If you use 2008 R2 or older you can't use OFFSET FETCH,
you have alternative to use
ROW_NUMBER()
and rewrite your query for example:with OFFSET
this query without OFFSET using
ROW_NUMBER()
为了解决我的问题,我使用了
To solve my Problem i used