根据另一个表值更新表

时间:2016-01-21 05:15:39

标签: sql sql-server

我有两张表Employees

EmpID | EmpName | EmpDob

WareHouseEmployeers

WarehouseEmpID | position | province

我需要根据Employee表的值更新WareHouseEmployers表。如何根据仓库省份和位置更新员工表的详细信息?

我试过这个,但它不起作用:

UPDATE Employee
SET a.EmpName = 'Steven', a.EmpDob = '5-5-1990'
FROM Employee a, WareHouseEmployee b,
WHERE 
    a.EmpID = b.WareHouseEmpID 
    AND position = 'manager', province = 'central'

有人可以帮我在SQL Server中执行此操作吗?

1 个答案:

答案 0 :(得分:1)

请使用此脚本

UPDATE a
SET a.EmpName = 'Steven' , a.EmpDob='5-5-1990'
FROM Employee a 
INNER JOIN WareHouseEmployee b ON a.EmpID = b.WareHouseEmpID 
                               AND position = 'manager' 
                               AND province = 'central'