日期:2014-05-18 浏览次数:20620 次
declare @num int=0 update tb set index=@num,@num=@num+1
------解决方案--------------------
create table qiujialongjjj(time date, team varchar(6), ID varchar(6), index_2 int, recordtime datetime)
insert into qiujialongjjj
select '2011-12-09', '日班', 'www', 1, '2011/12/9 17:25:05' union all
select '2011-12-09', '日班', 'www', 3, '2011/12/9 17:25:26' union all
select '2011-12-09', '日班', 'www', 4, '2011/12/9 17:27:24'
update a
set a.index_2=b.rn
from qiujialongjjj a
inner join
(select row_number() over(order by (select 0)) rn,* from qiujialongjjj) b
on a.recordtime=b.recordtime
select * from qiujialongjjj
time team ID index_2 recordtime
---------- ------ ------ ----------- -----------------------
2011-12-09 日班 www 1 2011-12-09 17:25:05.000
2011-12-09 日班 www 2 2011-12-09 17:25:26.000
2011-12-09 日班 www 3 2011-12-09 17:27:24.000
(3 row(s) affected)