if exists (SELECT table2.[name] from table2 ,table1
where table1.num=table2.num)
begin
declare @aa varchar(20)
declare aa cursor for
SELECT table2.[name] from table2 ,table1 where table1.num=table2.num
open aa
fetch next from aa into @aa
while @@fetch_status=0
begin
update table1
set [name]=@aa
where current of aa
fetch next from aa into @aa
end
close aa
deallocate aa
end