--有ID
1.
select top (b-a) * from 
(select top b * from tablename order by id) order by id desc2.
select top n * from tablename order by id desc

解决方案 »

  1.   

    1.
    select top (b-a) * from     --b-a要取数值
    (select top b * from tablename order by id) c order by id desc2.
    select top n * from tablename order by id desc
    --下面在本地测试成功
    1.
    select top 5 * from 
    (select top 10 * from T_Employee order by nid) c order by nid desc2.
    select top 5 * from T_Employee order by nid desc
    select * from dbo.T_Employee
      

  2.   

    因为 sql server 2000没有limit关键字,只能用id来算某一区间记录,好像2005会加入limit关键字
      

  3.   

    其实Sqlserver 2000并没有考虑基于WEB的BS系统开发,
    所有有时觉得MySql都有的东西 ,居然Sqlserver 2000没有.等待Sqlserver2005出来了要好生看看!
    我觉得在BS开发上功能应该加强了很多毕竟现在BS是主流
      

  4.   

    1 从a行到b行之间的记录
    select top b-a+1 * from table where id not in(select top b-1 id from table)

    select top n * from tablename order by id desc
      

  5.   

    select * from (select top b id from 表) B
    where B.id not in (select top a id from 表)
      

  6.   

    用Not in效率不太好!!还是等2005出来就好了
      

  7.   

    借助临时表:
    select identity(int,1,1) as rowid,* into #T from 表select * from #T where rowid between a and bselect top n * from #T order by rowid desc
      

  8.   

    是没有id的我用的也是 libin_ftsafe(子陌红尘) ( ) 的方法
    妈的,就感觉效率太低了。
    而且,用一个中间表还不行,不知道内部被做了什么优化public ResultSet getpageinfo(DBConnection db, String sql, int page)
    throws Exception
    {
    ResultSet rs = null;
    try{
    int i = sql.toLowerCase().indexOf("select ");
    if(i == -1){
    throw new Exception("error sql of no select");
    }
    String subsql = sql.substring(i + "select".length());
    sql = "select top " + (page * this.rowsperpage) + " " + subsql;
    //create page info
    sql = "select identity(int) as empriser_id, * into #empriser_temp1 from (" + sql + ") as temp";
    sql += this.linedelim + "select * into #empriser_temp2 from #empriser_temp1 where empriser_id > " + (page - 1) * this.rowsperpage;
    sql += this.linedelim + "alter table #empriser_temp2 drop column empriser_id";
    sql += this.linedelim + "select * from #empriser_temp1";
    sql += this.linedelim + "drop table #empriser_temp1" + this.linedelim + "drop table #empriser_temp2";
    rs = db.executeQuery(sql);
    }finally{ }
    return rs;
    }
      

  9.   

    倒數的話,很笨的方法
    declare @_count int,@Rowcount int
    set @_count=1set @Rowcount=(select count(*) from table1)
    select @Rowcountset @_count=@Rowcount-@_count-----正數的行數exec('
    select top 1 User_ID from table1 where User_ID not in
    (select top '+@_count+' User_ID from table1)
    ')
      

  10.   

    没id
    有id就没有这种问题了