locked
Updating a column in 1 table with value from another column in another table RRS feed

  • Question

  • Updating a column in 1 table with value from another column in another table

    Why the following code doesn't work?

    UPDATE TableX INNER JOIN TableY ON TableX.UserID = TableY.UserID
    SET TableX.DepartmentID = [tabley].[departmentID];

     

    Thursday, June 16, 2011 4:17 PM

Answers

  • Try :

    UPDATE TableX 
    SET TableX.DepartmentID = Y.[departmentID]
    From TableX X
    INNER JOIN TableY Y ON X.UserID = Y.UserID 
    

     

     


    Best regards
    • Marked as answer by qkc Thursday, June 16, 2011 4:24 PM
    Thursday, June 16, 2011 4:19 PM

All replies

  • Try :

    UPDATE TableX 
    SET TableX.DepartmentID = Y.[departmentID]
    From TableX X
    INNER JOIN TableY Y ON X.UserID = Y.UserID 
    

     

     


    Best regards
    • Marked as answer by qkc Thursday, June 16, 2011 4:24 PM
    Thursday, June 16, 2011 4:19 PM
  • UPDATE X

    SET X.DepartmentID = Y.DepartmentID

    FROM

    TableX X

    INNER JOIN 

    TableY Y

    ON

    X.UserID = Y.UserID


    Thanks, Cool Mind -- If you find my answer helpful, please mark it as Answer.
    Thursday, June 16, 2011 4:25 PM