查询N-M条记录。
select IDENTITY(int,1,1) as iid,* into #temptable from yourtable
select top M * from #temptable where iid>=NOR:select top M * from yourTable where id not in(select top N-1 id from table)
ID为表具有唯一值的任何字段

解决方案 »

  1.   

    不能用 limit 子句吗,SQL Server 不支持 limit 子句吗用楼上的第二种方法是不是有点太麻烦了,如果我的数据库很大,要浪费很多时间
    哦,还有个问题要澄清,主键为一个字符串。
      

  2.   

    declare @ table (COL_NO char(2) PRIMARY KEY ,COL_QTY int)
    insert @ values ('A',5)
    insert @ values ('be',                 5)
    insert @ values ('cs',                 5)
    insert @ values ('y',                 6)
    insert @ values ('e',                 6)
    insert @ values ('f',                 6)
    insert @ values ('g',                 7)
    insert @ values ('h',                 7)
    insert @ values ('i',                 7)--以下这句相当于"蚂蚁"的
    --select top M * from yourTable where id not in(select top N-1 id from table)
    Select top 2 * from @ where col_no not in (select top 3 col_no From @)
      

  3.   

    select top {n-m+1} * from (select top {n} from table order by {key} desc)其中{}中的需要你修改。
      

  4.   

    sorry!更正为:select top {n-m+1} * from (select top {n} from table) order by {key} desc
    其中{}中的需要你修改。
      

  5.   

    CRAZYFOR兄的好像不行哦
    GZ ing
      

  6.   

    select IDENTITY(int, 1,1) AS ID_Num,* into #temp from 表
    select * from #temp where ID_Num>10 and ID_Num<=20
      

  7.   

    exec('SELECT Top '+cast(@PageSize as varchar)+' * FROM T WHERE SortField NOT IN (SELECT TOP '+cast(@PageSize* @Pagei as varchar)+' SortField from T )')
      

  8.   

    谢谢大家,我终于想起来了,limit 子句是用在 MySql中的在SQL-Server中,取出第n条到第m条记录可以这样写例如:
    从publish 表中取出第 n 条到第 m 条的记录:
    SELECT TOP m-n+1 *
    FROM publish
    WHERE (id NOT IN
              (SELECT TOP n-1 id
             FROM publish))id 为publish 表的关键字