您的位置:首页 > 其它

写了一个分页存储过程把总记录数也写到返回表的每行了

2007-01-10 14:30 489 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: