![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I am attempting to update one column in a table with the value from a second table, using the code below: UPDATE TABLEA SET (PYMT_BEFORE_MOD) = (SELECT NEW_PYMT_BEFORE_MOD FROM TABLEB WHERE TABLEB.ACCOUNT = TABLEA.ACCOUNT) There are 16 rows out of 600 that meet criteria that I want to update. But the statement above updated all 600 rows with NULL. What am I doing wrong? |
#3
| |||
| |||
|
|
Hi Joe, On 27.01.11 16:59 , Joe wrote: I am attempting to update one column in a table with the value from a second table, using the code below: UPDATE TABLEA SET (PYMT_BEFORE_MOD) = *(SELECT NEW_PYMT_BEFORE_MOD * * * * * * * * * * * * * FROM TABLEB * * * * * * * * * * * * * WHERE *TABLEB.ACCOUNT = *TABLEA.ACCOUNT) There are 16 rows out of 600 that meet criteria that I want to update. * *But the statement above updated all 600 rows with NULL. What am I doing wrong? Several things: 1) you are missing the WHERE clause for the UPDATE statement 2) your SELECT statement most likely does not return a single value or returns NULL If you do not specify a where clause for the update statement, all rows are updated. What do you get when you run the following statement: SELECT NEW_PYMT_BEFORE_MOD FROM TABLEB WHERE *TABLEB.ACCOUNT = *TABLEA.ACCOUNT -- Helmut K. C. Tessarek DB2 Performance and Development /* * *Thou shalt not follow the NULL pointer for chaos and madness * *await thee at its end. */ |
#4
| |||
| |||
|
|
it returns the 16 rows of data that I expect. So I think you are saying that I need to have an additional WHERE clause outside of the last right parenthesis? |
#5
| |||
| |||
|
|
UPDATE TABLEA SET (PYMT_BEFORE_MOD) = (SELECT NEW_PYMT_BEFORE_MOD FROM TABLEB WHERE TABLEB.ACCOUNT = TABLEA.ACCOUNT) UPDATE TABLEA |
![]() |
| Thread Tools | |
| Display Modes | |
| |