use pubs
go
if exists(select name from sysobjects where name='Title_pubs' and type='p')
drop procedure Title_pubsgocreate procedure Title_pubs
@pagemax int=5,
 @pagesize int=1,
 @cells intas if pagesize<>1
begin
select top @pagemax * from titles where title_id not in(select top @cells title_id from titles order by title_id asc) order by title_id asc 
end
else
begin
select top @pagemax * from titles
end

解决方案 »

  1.   

    use pubs
    go
    if exists(select name from sysobjects where name='Title_pubs' and type='p')
    drop procedure Title_pubsgocreate procedure Title_pubs
    @pagemax int=5,
     @pagesize int=1,
     @cells intas if pagesize<>1
    begin
    exec('select top '+@pagemax+' * from titles where title_id not in(select top '+@cells+' title_id from titles order by title_id asc) order by title_id asc')
    end
    else
    begin
    exec('select top '+@pagemax+' * from titles')
    end
      

  2.   

    top后只能接常数,试试看这个use pubs
    go
    if exists(select name from sysobjects where name='Title_pubs' and type='p')
    drop procedure Title_pubsgocreate procedure Title_pubs
    @pagemax int=5,
     @pagesize int=1,
     @cells intas if pagesize<>1
    begin
    exec('select top '+@pagemax+' * from titles where title_id not in(select top @cells title_id from titles order by title_id asc) order by title_id asc') 
    end
    else
    begin
    exec('select top '+@pagemax+' * from titles')
    end
      

  3.   

    use pubs
    go
    if exists(select name from sysobjects where name='Title_pubs' and type='p')
    drop procedure Title_pubsgocreate procedure Title_pubs
    @pagemax int=5,
     @pagesize int=1,
     @cells intas if pagesize<>1
    begin
    exec ('select top '+ @pagemax +'* from titles where title_id not in(select top  '+@cells +' title_id from titles order by title_id asc) order by title_id asc ')
    end
    else
    begin
    exec('select top ' +@pagemax+ ' * from titles')
    end