代码改变世界

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

2011-02-14 13:25  于为源  阅读(396)  评论(0编辑  收藏  举报

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