方式一
select top @pageSize * from company where id not in
(select top @pageSize*(@pageIndex-1) id from company)
方式二ROW_NUMBER()OVER
--ROW_NUMBER() 就是生成一个有顺序的行号,而他生成顺序的标准,就是后面紧跟的OVER(ORDER BY ID)
--还必须添加OVER语句以便告诉SQL Server你希望怎样添加行序号。
select getdate()
select * from company where id in (
--搜索出settable表中所有的编号,也就是company表中的id,这里只不过要得到num(即有顺序的编号)
select id from
--搜索出出表中的所有的id,并且新建一列num用来存取排序的编号,并且把这张表赋值给settable
(select id,row_number() over (order by id) as
num from company)
as settable
--添加搜索条件页索引和页大小
where num between (@pageIndex-1)*@pageSize+1 and @pageIndex*@pageSize)
select getdate()
方式三
SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY id asc) AS rownum,
id
FROM company ) AS D
WHERE rownum BETWEEN (@pageIndex-1)*@pageSize+1 AND @pageIndex*@pageSize
ORDER BY id asc