use pubs
select city into #temp  from dbo.authors order by 1
select identity(int,1,1) as id,city into #T from #temp
select * from #t

解决方案 »

  1.   

    create table tab (col char(3))
    insert into tab values('AAA')
    insert into tab values('BBB')
    insert into tab values('CCC')
    select col,(select count(t2.col)+1 from tab t2 where t2.col<t1.col) as id
    from tab t1
    order by col
    注意:此列(此处为col)不能有重复!
      

  2.   

    看来很难做到不用创建临时表或另建一个表来实现了,因为没有 INTO 子句的select 语句是不可用 identity()的