sql語句的分頁技術

alter proc T_categories
(
	@pageIndex int ,
	@pageCount int 
)
as
begin
select top (@pageCount) CategoryName
	from Categories
	 where Categories.CategoryName not in
		(select top ((@pageIndex-1)*@pageCount) CategoryName from Categories order by Categories.CategoryID) order by Categories.CategoryID

end

exec T_categories 2,2

select CategoryName from Categories order by CategoryID

這是rowNumber的分頁技術sql

alter proc T_RowNumber
(
	@pageSize int,
	@pageIndex int
)
as 
begin
	with t_RowNumber 
	as
	(
		select ROW_NUMBER() over(order by Products.ProductID) as RowNum , * from Products
	)
	
	select * from t_RowNumber where RowNum >= ((@pageIndex-1) * @pageSize +1) and RowNum <= ( @pageIndex * @pageSize) order by ProductID
end

exec T_RowNumber 5, 2
相關文章
相關標籤/搜索