Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Posts
    5

    Unanswered: multiple update in single query based on different conditions

    i want to execute 3 update commands in single query like multiple inserts:--
    following query is getting executed priperly in DB2 command center as it treats it as 3 different queries.

    update ppymt_pen_pct set ppymt_pen_pct = ? where arr_id_app = ? and ppymt_pen_ind = ? and yr_num = ?;update ppymt_pen_pct set ppymt_pen_pct = ? where arr_id_app = ? and ppymt_pen_ind = ? and yr_num = ?;update ppymt_pen_pct set ppymt_pen_pct = ? where arr_id_app = ? and ppymt_pen_ind = ? and yr_num = ?;

    What i want is to update 3 rows based on diff where clauses in single statement.

    Any help is really appreciated.

    subhash

  2. #2
    Join Date
    May 2003
    Location
    San Juan, PR
    Posts
    18
    I am not clear about your requirement, but if you want to update a column with a value which depends on a given condition, you can try the next statement:

    UPDATE TBL1 A SET A.COL1 =
    ( CASE WHEN A.C2 = ? AND A.C3 = ? AND A.C4 = ? THEN ?
    WHEN A.C2 = ? AND A.C3 = ? AND A.C4 = ? THEN ?
    ELSE ?
    END )
    WHERE ( A.C2 = ? AND A.C3 = ? AND A.C4 = ? ) OR
    ( A.C2 = ? AND A.C3 = ? AND A.C4 = ? ) OR
    ( A.C2 = ? AND A.C3 = ? AND A.C4 = ? )

    good luck,
    saludos, aloz.

  3. #3
    Join Date
    Oct 2003
    Posts
    8

    Re: multiple update in single query based on different conditions

    Use CASE WHEN expression , that will resolve your problem.

    for sytax check SQL reference Guide


    Let me know if any question


    LekhaRaju Ennam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •