Reputation:
How can we write an update sql statement that would update records and the 'set' value changes every time?
For example: If we have records like this
SomeNumber SomeV CurCode WhatCodeShouldBe
200802754 432 B08 B09
200802754 432 B08 B09
200802754 432 B08 B09
200808388 714 64B C00
200804119 270 64B C00
I wish to update each 'SomeNumber' record so that 'CurCode' will be same as 'WhatCodeShouldBe'
Thanks for any help!
Upvotes: 1
Views: 557
Reputation: 53844
update a
set
3rdColumn = b.2ndColumn
from
tableA a
inner join tableB b
on a.linkToB = b.linkToA
That is based on your new comments
Upvotes: 1
Reputation:
i have got that data by forming some temptables and gathering information from different tables. :( updating this temp table wont be a help...I need to be able to carry the changes over to the original table. I'll try to give better example...
Table A: 200802754 432 B08 200802754 432 B08 200802754 432 B08 200808388 714 64B 200804119 270 64B
Table B 432 B09 432 B09 432 B09 714 C00
So I want to be making 3rd column of table A same as second column of table B...joining the tables on column 2. 200804119 270 64B C00
Upvotes: 0
Reputation: 48379
Assuming that the new code is stored in another column, i.e. WhatCodeShouldBe
, in the example above, then the statement looks something like:
UPDATE table SET CurCode = WhatCodeShouldBe
substituting in the actual column names. This essentially tells the DBMS, "for every row, set the code column to whatever the value is in this other column, for each row".
Upvotes: 0