陋室铭
永远也不要停下学习的脚步(大道至简至易)

ALTER PROCEDURE [dbo].[a_Example]
 @startIndex INT ,--每页的开始记录的索引
 @pageSize INT --每页记录数
AS
--取出记录总数 插入@RecordCountTable临时表
declare @RecordCountTable table(RecordCount int)
insert into @RecordCountTable SELECT count(*) AS RecordCount FROM InOut_InOut_InOutBed
--直接用
begin
 select * from
    (
      SELECT row_number() OVER (ORDER BY InOutBedID DESC)AS Row,*
   from
        InOut_InOut_InOutBed
   LEFT JOIN
        @RecordCountTable ON 1=1
 )
    as
      TemporaryTable
 where
   row between @startIndex and @startIndex+@pageSize-1
end

或者:
ALTER PROCEDURE [dbo].[a_Example]
 @startIndex INT ,--每页的开始记录的索引
 @pageSize INT --每页记录数
AS
--取出记录总数 插入@RecordCountTable临时表
declare @RecordCountTable table(RecordCount int)
insert into @RecordCountTable SELECT count(*) AS RecordCount FROM InOut_InOut_InOutBed
--虚拟视图
begin
--取出内容 每行左连记录总数 虚拟视图orderList
WITH orderList AS
(
SELECT row_number() OVER (ORDER BY InOutBedID DESC)AS Row,*
from InOut_InOut_InOutBed
LEFT JOIN @RecordCountTable ON 1=1
)
--取出虚拟视图orderList中分页内容
SELECT *
FROM orderlist
WHERE row between @startIndex and @startIndex+@pageSize-1
end

posted on 2007-01-10 14:30  宏宇  阅读(705)  评论(1编辑  收藏  举报