一、Entity Framework的Linq语句的分页写法:

 var datacount  = test.OrderBy(t => t.testID)
                    .Skip(pageSize * (pageIndex - 1))
                    .Take(pageSize).ToList();

二、SQL Server分页的SQL语句写法:

select
top (需要显示的条目数) *
from
DBTest
where TestID not in
(select top (需要剔除的条目数) TestID from DBTest)

三、SQL Server分页的存储过程写法:

第一种:

create proc proc_TestPage
@PageIndex  int --第几页
@PageSize  int  --每页显示的条数
@pageCount int output	--总的页数,因为需要显示页数,因此是个输出参数
as
declare @datacount int	--总数据条数
select @datacount=count(*) from DBTest--获得总数据条数值并赋给参数
set @pageCount=ceiling(1.0*@datacount/@pageSize)	--获得总页数,并赋给参数
select top(@PageSize) *  from DBTest where TestID not int (select top(@PageSize*(@PageIndex-1)) from DBTest)
select @PageCount=Count(*) from DBTest

第二种:

create proc P_Test	--创建存储过程P_Test
@pageSize int,	--每页数据条数
@pageIndex int,	--当前页数(页码)
@pageCount int output	--总的页数,因为需要显示页数,因此是个输出参数
as
declare @datacount int	--总数据条数
select @datacount=count(*) from DBTest --获得总数据条数值并赋给参数
set @pageCount=ceiling(1.0*@datacount/@pageSize)	--获得总页数,并赋给参数
--接下来是获得指定页数据
select * from
(select *,row_number() over(order by TestID ) as num from DBTest) as temp
where num between @pageSize*(@pageIndex-1)+1 and @pageSize*@pageIndex

作者:|TomLucas|,原文链接: https://www.cnblogs.com/lucasDC/p/17233400.html

文章推荐

记一次 Oracle 下的 SQL 优化过程

从GFS到GPT,AI Infra的激荡20年

Vue跨域详解

Java设计模式-建造者模式

.net使用nacos配置,手把手教你分布式配置中心

聊聊Redis sentinel 机制

Generative Pre-trained Transformer(GPT)模型技术初探

【过滤器设计模式详解】C/Java/JS/Go/Python/TS不同语言实现

重学c#系列—— explicit、implicit与operator[三十四]

linux网络编程中的errno处理

Java线程池ThreadPoolExecutor极简教程

drools中then部分的写法