If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > multiple update in single query based on different conditions

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-28-03, 09:28
subhash13 subhash13 is offline
Registered User
 
Join Date: Aug 2003
Posts: 5
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
Reply With Quote
  #2 (permalink)  
Old 10-28-03, 17:59
aloz aloz is offline
Registered User
 
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.
Reply With Quote
  #3 (permalink)  
Old 10-29-03, 10:26
db2os390udbdba db2os390udbdba is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On