就是完成       select       @max=max(ID)       from       (select       top       N       from       t)的功能 ============================================================================== 我不想有select       top       N       from       t操作的开销谢谢

解决方案 »

  1.   

    select top N @ID=ID from T
      

  2.   

    SET ROWCOUNT 100
    GOselect @max=max(ID) from  T
    GO
      

  3.   

    SET ROWCOUNT 4
    GOdeclare @t table(id int)
    insert @t select 1 
    union select 2 
    union select 3 
    union select 4 
    union select 5 
    union select 6select max(ID) from  @t
    GO /*----------- 
    4(所影响的行数为 1 行)*/
      

  4.   

    SET ROWCOUNT 3
    GOdeclare @t table(id int)
    insert @t select 1 
    union select 2 
    union select 3 
    union select 4 
    union select 5 
    union select 6select max(ID) from  @t
    GO /*----------- 
    3(所影响的行数为 1 行)*/