1

I have two tables Employees

EmpID | EmpName | EmpDob

and WareHouseEmployeers

WarehouseEmpID | position | province

I need to update the Employee table according to the WareHouseEmployers table's values. How do I update the details about the employee table according to warehouse province and position?

I have tried this but it's not working:

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'

Can someone please help me to do that in SQL Server?

TT.
  • 15,774
  • 6
  • 47
  • 88

1 Answers1

1

Please use this script

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'
TT.
  • 15,774
  • 6
  • 47
  • 88
Sanu Antony
  • 364
  • 4
  • 15
  • this also give erro: `a.EmpName and a.EmpDob` could not be found – SteavenJohns Jan 21 '16 at 05:35
  • its typo. Set Empployee to Employees – Ashish Rajput Jan 21 '16 at 05:54
  • A good read about "UPDATE FROM" "I guess that many people using UPDATE … FROM on a daily basis do so without being aware that they are violating all SQL standards." LINK http://sqlblog.com/blogs/hugo_kornelis/archive/2008/03/10/lets-deprecate-update-from.aspx – Neeraj Prasad Sharma Jan 21 '16 at 06:53
  • @NeerajPrasadSharma I for one do not agree with that article. And **every** major RDBMS violates SQL Standards in some way or form... – TT. Jan 21 '16 at 09:58