34,837
社区成员




create table tb(I int,S datetime,E datetime)
go
insert into tb select 5, '2008/02/02', '2008/05/02'
insert into tb select 5, '2008/03/02', '2008/05/02'
insert into tb select 5, '2008/04/02', null
go
select i,convert(char(10),s,120) as s,convert(char(10),e,120) as e from tb
update tb
set e=(select min(s) from tb a where a.i=tb.i and a.s>tb.s)
select i,convert(char(10),s,120) as s,convert(char(10),e,120) as e from tb
go
drop table tb
go
i s e
----------- ---------- ----------
5 2008-02-02 2008-05-02
5 2008-03-02 2008-05-02
5 2008-04-02 NULL
(3 行受影响)
(3 行受影响)
i s e
----------- ---------- ----------
5 2008-02-02 2008-03-02
5 2008-03-02 2008-04-02
5 2008-04-02 NULL
(3 行受影响)