日期:2014-05-18 浏览次数:20623 次
create table a(acno varchar(10),acname varchar(10)) insert into a values('12345', 'abcde') insert into a values('12345', null ) insert into a values('12345', 'abcde') insert into a values('12344', 'bcdef') go update a set acname = (select top 1 acname from a where acno = t.acno and acname <> '' and acname is not null) from a t where acname = '' or acname is null select * from a /* acno acname ---------- ---------- 12345 abcde 12345 abcde 12345 abcde 12344 bcdef (所影响的行数为 4 行) */ drop table a
------解决方案--------------------
前面一个有错
update table_name set acname = (select top 1 t.acname from table_name t where t.acno = table_name.acno and t.acname is not null) where acname is null