SQL-update多条Select出来的数据
好多朋友喜欢用游标解决此问题,但是执行速度狂慢!
其实解决起来很简单了:
先来个简单的:
把FLowER的Am_employee表的email,dept_id,ext_no多条数据按emp_no对应update到EmpBaseInfo表中:
update EmpBaseInfo
set email=b.Mail_account,dept_id=b.dept_code,ext_no=b.ext_no
from flower.flower.dbo.am_employee b
where b.emp_no=EmpBaseInfo.emp_no
复杂一点的:
多表select,并将结果对应插入到指定的表中:
update EmpBaseInfo
set Job_Rank=b.level_number
from flower.flower.dbo.am_employee a,flower.flower.dbo.am_level b,flower.flower.dbo.am_approver_level c
where a.emp_id=c.emp_id and b.level_number=c.level_number and a.emp_no=EmpBaseInfo.emp_no
取别名的:
update x
set Job_Rank=b.level_number
from flower.flower.dbo.am_employee a,flower.flower.dbo.am_level b,flower.flower.dbo.am_approver_level c,EmpBaseInfo x
where a.emp_id=c.emp_id and b.level_number=c.level_number and a.emp_no=x.emp_no
喜欢请赞赏一下啦^_^