不用临时表或临时变量取分页存储过程

begin 
declare @rowStart int ,@rowEnd int
set @rowStart = (@pageIndex - 1)*@pageSize + 1 
set @rowEnd = @rowStart + @pageSize -1 
set @sql = 'select * from( select row_number() over(order by Date desc) as rowIndex, test.* from [dbo].[testTable] as test) as t where t.rowIndex between '+ @rowStart +' and '+ @rowEnd +'' 
end

 

说明:按Date倒序排序查询testTable表分页 @pageIndex 传入的页索引, @pageSize 传入的每页条数, select row_number() over(order by Date desc) as rowIndex 行号

posted @ 2009-12-29 15:09  风w  阅读(393)  评论(0编辑  收藏  举报