select isnull((select count(1) from sysobjects where id<t.id),0) as num from sysobjects t

解决方案 »

  1.   

    一个嵌套的子查询,isnull(select count(1) from sysobjects where id<t.id,0) as num
    求出总数
      

  2.   

    对sysobjects进行查询,比每一个ID小的记录有多少条,如果为NULL,则显示为0。
    因为比第一个ID小的记录统计出来肯定是NULL,因此结果集第一条记录肯定显示为0。
    如果所有的ID都不重复,那么显示的结果集肯定是按照0,1,2这样的顺序,而且最后一个数字肯定是sysobjects记录数-1。
      

  3.   


    select 
        dateadd(dd,num,'2012-01-01') dt
    from 
        (select isnull((select count(1) from sysobjects where id<t.id),0) as num from sysobjects t) awhere
        dateadd(dd,num,'2012-01-01')<='2012-01-31'为什么要用sysobjects这个表,而不用其它的表?