0

Im a Newbie to SQL Server

Could you help me out with updating a table within the same database -the Database Name is Staff.

I have 2 tables (I am trying to update the StaffID field in tblstaff with data from StaffID field in tblStaff_old )

the old one is tblstaff_old the new one is tblstaff

I have tried this code but is keeps telling me 0 rows updated.

UPDATE dbo.tblStaff
SET StaffID = dbo.tblStaff_Old.StaffID
FROM dbo.tblStaff_Old;

Thank You :)

Alta
  • 1
  • 1

1 Answers1

0

You need to JOIN the two tables, and specify in the ON clause how those tables are joined (i.e. the below code, substitute id for however thse tables are joined)

Also note that I used table aliases s and so for readability.

UPDATE dbo.tblStaff
SET s.StaffID = so.StaffID
FROM dbo.tblStaff_Old so
   JOIN dbo.tblStaff s ON so.id = s.id
Jim Horn
  • 879
  • 6
  • 14