Hi
if i have a table called tblEmployee with these fields
ID autonumber , PK
EmployeeCode int
Salary int
JobTitle short text
now if have another table with the same fields but with new and updated information,
how to write a sql update statement in order to update the original table with new salary and job title?
Regrads
SQL update statement
-
- BronzeLounger
- Posts: 1267
- Joined: 01 May 2016, 09:58
-
- Administrator
- Posts: 78628
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: SQL update statement
Can we match the old and new table on ID? Or on EmployeeCode?
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1267
- Joined: 01 May 2016, 09:58
Re: SQL update statement
the old and new table should match on employeeCode
so employeecode=0001 in the old table is same as the employeecode=0001 in the new table
regards
so employeecode=0001 in the old table is same as the employeecode=0001 in the new table
regards
-
- Administrator
- Posts: 78628
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: SQL update statement
Try this - let me know if you get an error:
UPDATE tblEmployee INNER JOIN tblOther ON tblEmployee.EmployeeCode=tblOther.EmployeeCode SET tblEmployee.Salary=tblOther.Salary, tblEmployee.JobTitle=tblOther.JobTitle
where tblOther is the name of the table with the updated information.
UPDATE tblEmployee INNER JOIN tblOther ON tblEmployee.EmployeeCode=tblOther.EmployeeCode SET tblEmployee.Salary=tblOther.Salary, tblEmployee.JobTitle=tblOther.JobTitle
where tblOther is the name of the table with the updated information.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1267
- Joined: 01 May 2016, 09:58
Re: SQL update statement
so the old and the updated table should have an inner join relationship!
thanks a lot, i will try this
thanks a lot, i will try this
-
- Administrator
- Posts: 78628
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- BronzeLounger
- Posts: 1267
- Joined: 01 May 2016, 09:58
-
- BronzeLounger
- Posts: 1267
- Joined: 01 May 2016, 09:58
Re: SQL update statement
if I want to update the old table based on two criteria like this sample below, how do it please many thanksHansV wrote:Try this - let me know if you get an error:
UPDATE tblEmployee INNER JOIN tblOther ON tblEmployee.EmployeeCode=tblOther.EmployeeCode SET tblEmployee.Salary=tblOther.Salary, tblEmployee.JobTitle=tblOther.JobTitle
where tblOther is the name of the table with the updated information.
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78628
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: SQL update statement
That would be
UPDATE NewData INNER JOIN OldData ON NewData.EmployeeCode=OldData.EmployeeCode AND NewData.Item_Code=OldData.Item_Code SET OldData.Qty=NewData.Qty
Please test on a copy of the database first.
UPDATE NewData INNER JOIN OldData ON NewData.EmployeeCode=OldData.EmployeeCode AND NewData.Item_Code=OldData.Item_Code SET OldData.Qty=NewData.Qty
Please test on a copy of the database first.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1267
- Joined: 01 May 2016, 09:58