SQL2000 中的问题
有一查询结果:
字段1 字段2
adf dfasdf
23r23 23rd
...
怎么在SOL 语句中加如一个列,形式如下:
字段1 字段2 字段3
adf dfasdf 1
23r23 23rd 2
...
123ddf 32rdfgf n
------解决方案--------------------create table T(字段1 varchar(10), 字段2 varchar(10))
insert T select 'adf ', 'dfasdf '
union all select '23r23 ', '23rd '
select 字段1, 字段2, 字段3=identity(int, 1, 1)
into #T
from T
select * from #T
--result
字段1 字段2 字段3
---------- ---------- -----------
adf dfasdf 1
23r23 23rd 2
(2 row(s) affected)
------解决方案--------------------沙发说得对
select *,a = identity(int,1,1) into #abc from 表
select * from #abc