日期:2014-05-17 浏览次数:20557 次
create table Patient(name varchar(10))
insert into Patient
select '张三' union all
select '李四' union all
select '王五' union all
select '孙六'
--更新
select identity(int,1,1) 'rn', name, ' ' 'newname'
into #t
from Patient
update a
set a.newname=case when a.rn%2=0 then left(c.name,1)+right(a.name,1)
else left(b.name,1)+right(a.name,1) end
from #t a
left join #t b on a.rn=b.rn-1
left join #t c on a.rn=c.rn+1
update a
set a.name=b.newname
from Patient a
inner join #t b on a.name=b.name
drop table #t
--结果
select name from Patient
/*
name
----------
李三
张四
孙五
王六
(4 row(s) affected)
*/