tags:

views:

242

answers:

5

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!

A: 

UPDATE yourtable SET CurCode = WhatCodeShouldBe

efficientjelly
A: 
UPDATE tableName SET CurCode = WhatCodeShouldBe
Jack Ryan
A: 

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".

Rob
A: 

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

Please edit you question to include this clarification
kristof
+1  A: 
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

kristof