我有两张桌子;
技术查找表
OSID OSValue
1 UNIX
2 ORACLE
3 .NET
4 SQL
5 SAP
------------------
员工技术
empID OSID
34 1
37 2
45 2
34 4
45 6
员工ID NO 37不再使用ORACLE。他转向SAP。那就是OSID应该在第二个表中从2更新为5。
我有一个临时表,其中包含技术和员工ID
的值请帮帮我 - 编写一个连接上述两个表的查询 - 查找SAP技术的ID,并使用该ID更新第二个表。
Update emp
Set emp.OSID = (Select OSID from technologylookup where OSValue = tmptbl.technologyname)
FROM employee_tech emp INNER JOIN #Temptbl tmptbl ON emp.emp_id = tmptbl.emp_id
答案 0 :(得分:3)
将查找表加入临时表,然后使用该表中的ID更新employee_tech表
Update emp
Set emp.OSID = tl.OSID
FROM employee_tech emp
INNER JOIN #Temptbl tmptbl
ON emp.emp_id = tmptbl.emp_id
INNER JOIN technologylookup tl
ON tl.OSValue COLLATE DATABASE_DEFAULT = tmptbl.technologyname
答案 1 :(得分:0)
从我的头脑中,未经测试:
update employee_tech
set osid = t.osid
from #Temptbl tmp
inner join employee_tech e on e.emp_id = tmp.emp_id
inner join technologylookup t on t.osvalue = tmp.technologyname
答案 2 :(得分:0)
如果临时表中的“技术”等于ID,则可以像这样更新。
UPDATE employee_tech
SET OSID = (SELECT technology FROM #Temptbl AS T INNER JOIN employee_tech AS E ON T.empID = E.empID)