NWilkie
NWilkie

Reputation: 156

Updating rows from a list of values

I'm trying to update a thousand or so rows in a DB2 table using lists of values in an excel spreadsheet. The spreadsheet has three essential columns of data in it, two of which identify which row in the table is needed, and the third row in the spreadsheet corresponds to incorrect records in the database table which need to be updated. I can easily identify and select the rows in question, however I am not sure how to update these rows from a list of values.

Table:

  ...  ID_1      ID_2       STATUS   ...
       1234      2345         A
       4321      5423         B

Spreadsheet:

ID_1       ID_2     STATUS 
1234       2345       B
4321       5423       A  

To select the records I copied the columns from the excel sheet, added apostrophes and commas and used

where id_1 in ('ID_1_a','ID_1_b'.....'ID_1_xxx')

Same thing for the second identifying column (ID_2). Can I somehow use this notation to update from the list of statuses? The spreadsheet contains other superfluous columns, and these are not the only columns in the table either.

Upvotes: 0

Views: 131

Answers (1)

paulmorriss
paulmorriss

Reputation: 2615

This does what I think you want to do:

Put a formula in cell D2 (if the spreadsheet is exactly as you have it there)

="update table set status='" & c2 & "' where id_1 = '"& a2 & "' and ID_2 = '" & b2 "'"

then copy it down the spreadsheet.

This generates SQL statements which you can then run on your database.

Upvotes: 2

Related Questions