今日学习心得:sqlserver2005分页查询存储过程

create procedure usp_ProductByCategory

(

@categoryID int,

@beginIndex int,

@endIndex int,

@docount bit

)

as

if(@docount=1)--说明只做统计计数

begin

select count(*) from ViewProduct where categoryid=@categoryid

end

else

begin

with tempbl as (select row_number() over (order by AddDate desc) as rownum,* from ViewProduct where cateoryid=@categoryId)

select * from tempbl where rownum between @beginindex and @endindex

end

作者:于为源 出处: http://www.cnblogs.com/yuanyuan/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/yuanyuan/p/1954262.html