Reputation: 67
I have two tables and one common column named code in both the tables. I want to update the values of a column named version in table A with column named set_version values in table B.But this should not add rows and only update values. How do I do that?
Upvotes: 0
Views: 124
Reputation: 67
All the above answers were correct.But to make it more perfect I would like to answer my question so that if anyone reads then he/she should get it in one glance....
What I have :
There are two tables 'A' and 'B' with one common column 'Code'
What I want :
Solution:
Structure in general
UPDATE targetTable
SET targetTable.targetColumn = s.sourceColumn
FROM targetTable t
INNER JOIN sourceTable s
ON t.matchingColumn = s.matchingColumn
Structure using my table and coumn names
UPDATE dbo.A
SET dbo.A.Version = s.Set_version
FROM dbo.A t
INNER JOIN dbo.B s
ON t.Code = s.Code
This will definitely help the one with my scenario!
Upvotes: 0
Reputation: 1270081
You would use update
with join
:
update a
set version = b.set_version
from a join
b
on <some join condition here that your question does not specify>;
The update
only updates existing rows. It does not add new rows to the table.
Upvotes: 1