存储过程:
CREATE  proc mypage
(@pagenum int,@typeid int,@maxnum int output)
as

SET NOCOUNT ON
declare @sql nvarchar(500)
declare @rownum int
declare @pagecount int
begin      
     select @maxnum=count(*) from article where classid=@typeid
     create table #change (id int)
     if @maxnum>10
        begin

             if @pagenum=1
                 select top 10 articleid,title,hits,dateandtime from article
             else
                 begin
                      set @rownum=(@pagenum-1)*10
                      set @sql=N'insert #change (id) select top '+cast(@rownum as char(100))+' articleid from article'
                      exec sp_executesql @sql
                      select TOP 10 articleid,title,hits,dateandtime from article where classid=@typeid and articleid not in (select id from #change)
                 end
        end
     else
         select articleid,title,hits,dateandtime from article
end
GO
posted on 2006-10-23 16:47  Eric Yao  阅读(124)  评论(0编辑  收藏  举报