在一个视图里面有三个字段是主键,请问如何实现分页!

解决方案 »

  1.   

    一般分页用not in 但有三个主键,就不行了.
    比如每页20,找第5页,id1,id2,id3为联合主键:
    1.用not exists
    select top 20 * from tab A 
    where not exists (select 1 from (select top 80 * from tab order by id1,id2,id3) T  where A.id1=T.id1 and A.id2=T.id2 and A.id3=T.id3)
    order by id1,id2,id32.用left join
    select top 20 A.* from tab A
    left join (select top 80 * from tab order by id1,id2,id3) T 
    on A.id1=T.id1 and A.id2=T.id2 and A.id3=T.id3)
    where T.id1 is null
    order by A.id1,A.id2,A.id3
      

  2.   

    奇怪,SQLSERVER版怎么会没人抢分???
      

  3.   

    CREATE PROCEDURE [dbo].[Get_PageList]
    @sqlstr nvarchar(4000), --查询字符串 
    @pagecount int, --第N页 
    @pagesize int --每页行数 
    AS
    BEGIN
      set nocount on 
      declare @P1 int, --P1是游标的id 
      @rowcount int 
      exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output 
      select @rowcount as 总行数,ceiling(1.0*@rowcount/@pagesize) as 页数,@pagecount as 当前页 
      set @pagecount=(@pagecount-1)*@pagesize+1 
      exec sp_cursorfetch @P1,16,@pagecount,@pagesize 
      exec sp_cursorclose @P1 
    endGO