select *,id=identity(int,1,1) into #t from table1 order by col1
go
select * from #t
go
drop table #t
go

解决方案 »

  1.   

    用临时表select IDD=identity(int,1,1),* into #T  from TABL1 
    select * from #T
      

  2.   

    不好,
    select *,d=identity(int,1,1) into #b from  table1 order by col1select *  from  #b  -----這裡面的d醫是查詢的序號
      

  3.   

    上边的老大们说的可以了,
    用一条语句是没有其他办法解决的,
    除了
    exec('select *,d=identity(int,1,1) into #b from table1 order by col1
          select * from #b
          drop table #b ')
      

  4.   

    select *,identity(int,1,1) as id into #t from table1 order by coll
      

  5.   

    Alter Table table1
      Add [ID] Identity[1,1]
    GO
    Select * from table1 Order By Coll
    GO
    Alter table table1
      drop column [id]