34,590
社区成员
发帖
与我相关
我的任务
分享
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
update table_name
set acname = (select top 1 from table_name t where t.acno = table_name.acno and t.acname is not null)
where acname is null
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