Update with change of setpoint

How can we write a sql update statement that will update the records and change the "set" value 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 want to update every "SomeNumber" record so that "CurCode" is the same as "WhatCodeShouldBe"

Thanks for any help!

+1


source to share


5 answers


update a
set
  3rdColumn = b.2ndColumn
from
  tableA a
  inner join tableB b
  on a.linkToB = b.linkToA

      



Based on your new comments

+1


source


UPDATE yourtable SET CurCode = WhatCodeShouldBe



0


source


UPDATE tableName SET CurCode = WhatCodeShouldBe 

      

0


source


Assuming the new code is stored in a different column i.e. WhatCodeShouldBe

, in the example above, the expression looks something like this:

UPDATE table SET CurCode = WhatCodeShouldBe

      

replacing the names of the actual columns. This is essentially what the DBMS says, "for each row, set a code column regardless of the value in that other column for each row."

0


source


I have this data, creating some confusion and gathering information from different tables. :( Updating this temp table will not help ... I need to be able to push the changes back to the original table. I will try to give a 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 make the 3rd column of the table the same as the second column of table B ... joining the tables in column 2. 200804119 270 64B C00

0


source







All Articles