0

I am updating two columns from 2 tables but getting Exception message:

The multi-part identifier "item_t1.Code" could not be bound

  UPDATE item_t0 
  SET 
     item_t0.p_enddate = DATEADD(d, -29, GETDATE()), 
     item_t1.Code = 'Inactive'
  FROM employee item_t0 
  JOIN dept item_t1 ON  item_t0.id = item_t1.empid  
  WHERE 
     (item_t0.p_enddate IS NOT NULL and item_t1.Code in ('Active', 'Pending')) AND 
     item_t0.p_empid = 11636
Zhorov
  • 28,486
  • 6
  • 27
  • 52
user739115
  • 1,117
  • 5
  • 20
  • 41
  • 1
    A similar [Q&A](https://stackoverflow.com/questions/15115759/update-multiple-tables-in-sql-server-using-inner-join/15116036). – Zhorov Nov 23 '20 at 08:27
  • 2
    You cannot update two tables in one UPDATE statement! https://stackoverflow.com/a/5321193/11305029 – droebi Nov 23 '20 at 08:29
  • Why in the world would you use table aliases that simply don't match the actual table names and only add confusion? Employees are items? Departments are Items? And does "d" REALLY save you that much effort over using "day" in your dateadd function? Which do you think is more easily understood? – SMor Nov 23 '20 at 14:56

0 Answers0