目前主要有2种方法
1,select * into #tmp from table
alter #tmp add cnt identity(1,1)
select * from #tmp
2,有一个可以唯一区分的列或列组合
select *,(select count(*)  from table t2 where t2.id<=t.id) as cnt from table t

解决方案 »

  1.   

    如果表里有主键:
    select (select count(*)+1 from mm a where a.主键>主键 and n1>50) as id,name from mm where n1>50
      

  2.   

    select identity(int, 1, 1) as sn, name into #tmp from mm where nl>50
    select * from #tmp
      

  3.   

    错了
    1,select * into #tmp from table
    alter #tmp add cnt int  identity(1,1)
    select * from #tmp
    2,要有一个可以唯一区分的列或列组合
    select *,(select count(*)  from table t2 where t2.id<=t.id) as cnt from table t
      

  4.   

    select identity(int,1,1) FID,name into #temp from from mm where nl>50
    select * from #temp
    drop table #temp
      

  5.   

    SELECT identity(int, 1, 1) id, name INTO # FROM mm WHERE nl>50
    SELECT * FROM #
      

  6.   

    select identity(int,1,1) FID,name into #temp  from mm where nl>50
    select * from #temp
    drop table #temp
      

  7.   

    select a.name into #A from MM a where a.nl>50
    alter table #A add  id int identity(1,1)
    select * from #A
      

  8.   

    create table #tem(no int identity,name varchar(20))
    insert #tem select name from  mm where n1>50
    select * from #tem
    drop table #tem