sqlserver 2000 的分页语句  网上有种写法是这样的:
 select top PAGESIZE * from 
            components where id not in (select top (PAGESIZE*(CURRENTPAGE-1)) id from 
                   components order by id)order by id 我想问 比如一张产品表里  有这些字段: id(主键 自增) name(产品名称)  sortid(产品分类)  
我想把 sortid = 2 的产品  分页查出来 应该怎么写啊这里的 sortid = 后面的 2 是变量

解决方案 »

  1.   

    declare @s varchar(8000)
    select  @s='select top '+ltrim(@PAGESIZE)+' * from  
      components where id not in (select top '+ltrim(@PAGESIZE*(@CURRENTPAGE-1))+' id from  
      components order by id)order by id  '
    exec(@s)
      

  2.   

    声明一个变量,用拼接的方式实现TOP参数传递,已经简单了。
      

  3.   

    SQL2005可以如以下:
     select top (@PAGESIZE) * from  
      components where id not in (select top (@PAGESIZE*(@CURRENTPAGE-1)) id from  
      components order by id)order by id  SQL2000只能用变量来拼。
      

  4.   

    昏了呀  好像和sortid没什么关系了啊。这么说吧 比如 有张服装表  3个字段 : id  name sortid
    sortid 表示  国产服装,进口服装等等分类  现在要吧  国产服装  取出来 分页显示  sql语句怎么写
    是sqlserver2000  不用存储过程  谢谢大侠们
      

  5.   


    select top 20 id,name,sortid from components  
    where sortid = '值' 
    and id > 10这个是第二页的,,,你测试哈巴,,我也是新手
      

  6.   

    declare @s varchar(8000)
    select @s='select top '+ltrim(@PAGESIZE)+' * from  
      components where sortid = '+@sortid+' and  id not in (select top '+ltrim(@PAGESIZE*(@CURRENTPAGE-1))+' id from  
      components sortid = '+@sortid+' order by id)order by id '
    exec(@s)
      

  7.   

    declare @s varchar(8000)
    select @s='select top '+ltrim(@PAGESIZE)+' * from  
      components where sortid = '+@sortid+' and id not in (select top '+ltrim(@PAGESIZE*(@CURRENTPAGE-1))+' id from  
      components where sortid = '+@sortid+' order by id)order by id '
    exec(@s)