下边是我写的,现在我想加一个返回总数用于分页的总数绑定declare @pagesize int,@pageNum int
set @pagesize=10
set @pageNum=1
select * from (
select *,row_number() over(order by 表) rn  
from 表) a
where rn between @pagesize*(@pageNum-1) and @pagesize*(@pageNum)-1

解决方案 »

  1.   


    declare @pagesize int,@pageNum int
    set @pagesize=10
    set @pageNum=1declare @count int
    select @count=count(*) from 表select *,@count as 总条数 from (
    select *,row_number() over(order by 表) rn   
    from 表) a
    where rn between @pagesize*(@pageNum-1) and @pagesize*(@pageNum)-1
      

  2.   

    大哥报错误,消息 4104,级别 16,状态 1,第 8 行
    无法绑定由多个部分组成的标识符 "dbo.Play"。
      

  3.   

    play是你的表吧?我给你写个例子,稍等
      

  4.   


    declare @play table (id int,col varchar(1))
    insert into @play
    select 1,'a' union all
    select 2,'b' union all
    select 3,'c' union all
    select 4,'d' union all
    select 5,'e' union all
    select 6,'f' union all
    select 7,'g' union all
    select 8,'h' union all
    select 9,'i' union all
    select 10,'j' union all
    select 11,'k' union all
    select 12,'l' union all
    select 13,'m' union all
    select 14,'n' union all
    select 15,'o'declare @pagesize int,
    @pageNum int
    set @pagesize=10
    set @pageNum=1declare @count int
    select @count=count(*) from @playselect *,@count as 总条数 from (
    select *,row_number() over(order by id) rn   
    from @play) a
    where rn between @pagesize*(@pageNum-1) and @pagesize*(@pageNum)/*
    id          col  rn                   总条数
    ----------- ---- -------------------- -----------
    1           a    1                    15
    2           b    2                    15
    3           c    3                    15
    4           d    4                    15
    5           e    5                    15
    6           f    6                    15
    7           g    7                    15
    8           h    8                    15
    9           i    9                    15
    10          j    10                   15
    */
    直接可以全选 运行。