--再加一条记录测试.
create table t1 (aa varchar(10),bb varchar(10))
insert t1
select '10','100'
union all select '10',''
union all select '10','300'
union all select '20','200'
union all select '20',''
select * from t1
create function get_bb(@aa varchar(10))
returns varchar(10)
as
begin
declare @re varchar(10)
select @re=
--select top 1
bb from t1 where bb<>'' and aa=@aa
return @re
end
update t1
set bb=dbo.get_bb(aa)
where bb=''
select * from t1
--
drop table t1
drop function get_bb
/**
更新前
aa bb
---------
10 100
10
10 300
20 200
20
create table t1 (aa varchar(10),bb varchar(10))
insert t1
select '10','100'
union all select '10',''
union all select '10','300'
union all select '20','200'
select * from t1
drop table t1
create function get_bb(@aa varchar(10))
returns varchar(10)
as
begin
declare @re varchar(10)
select @re=
--select top 1
bb from t1 where bb<>'' and aa=@aa
return @re
end