How to update multiple columns in single update statement in DB2

Superman picture Superman · Mar 26, 2014 · Viewed 147.1k times · Source

I want to update multiple columns of a table in DB2 with single Update statement.

Any hint or idea will be appreciable. Thanks.

Answer

Gordon Linoff picture Gordon Linoff · Mar 26, 2014

The update statement in all versions of SQL looks like:

update table
    set col1 = expr1,
        col2 = expr2,
        . . .
        coln = exprn
    where some condition

So, the answer is that you separate the assignments using commas and don't repeat the set statement.