truncate table table2insert table2(y_id,Y_SALARY) select y_id,null from (select y_no,min(y_id) as y_id from table1 group by y_no) as twhile exists (select 1 from table2 where Y_SALARY is null) begin set rowcount 1 update table2 set Y_SALARY=cast(1000+rand()*1000 as int) where Y_SALARY is null set rowcount 0 end--检查结果 select * from table2
select y_id,null
from (select y_no,min(y_id) as y_id from table1 group by y_no) as twhile exists (select 1 from table2 where Y_SALARY is null)
begin
set rowcount 1
update table2 set Y_SALARY=cast(1000+rand()*1000 as int)
where Y_SALARY is null
set rowcount 0
end--检查结果
select * from table2