Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

EXECUTE MULTIPLE UPDATE STATEMENTS

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
i.see.the.truth

New User


Joined: 21 Sep 2007
Posts: 8
Location: CHENNAI

PostPosted: Mon Sep 17, 2012 6:15 pm    Post subject: EXECUTE MULTIPLE UPDATE STATEMENTS
Reply with quote

Hi,

I have the following update statements to be executed with the below mentioned condition. Is there any DB2 function that can achieve the same result.

Statement 1 -

UPDATE TABLE_1
SET COLUMN_1 = 'VAL1'
WHERE COLUMN_3 = 1

Statement 2 -

UPDATE TABLE_1
SET COLUMN_2 = 'VAL2'
WHERE COLUMN_3 = 2

Condition -

Statement 2 should be executed when no rows are updated by Statement 1. Is there any way this can be done using SQL only?
Back to top
View user's profile Send private message

Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Sep 17, 2012 7:50 pm    Post subject:
Reply with quote

Untested:
Code:
UPDATE TABLE_1
SET COLUMN_1 =
CASE
    WHEN COLUMN_3 = 1 THEN 'VAL1'
    WHEN COLUMN_3 = 2 THEN 'VAL2'
END


Can COLUMN_1 be NULL? If not, you'll run in to the 'error' with above SQL.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6967
Location: porcelain throne

PostPosted: Mon Sep 17, 2012 8:11 pm    Post subject:
Reply with quote

Quote:
Statement 2 should be executed when no rows are updated by Statement 1.


i would interpret this to mean if the UPDATE ...WHERE COLUMN_3 = 1
returns an sqlcode of +100 or sqlerrcd(3) = 0
then update WHERE COLUMN_3 = 2
Back to top
View user's profile Send private message
i.see.the.truth

New User


Joined: 21 Sep 2007
Posts: 8
Location: CHENNAI

PostPosted: Tue Sep 18, 2012 11:01 am    Post subject:
Reply with quote

Yes Dick Brenholtz, u r right, can this be done using SQL only, without using a programming language?

Thanks
Soumen
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
No new posts Unable to create multiple files using... mbattu COBOL Programming 3 Fri May 05, 2017 5:35 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
This topic is locked: you cannot edit posts or make replies. SDSF multiple spool datasets extracte... PJAlarcon CLIST & REXX 1 Fri Apr 21, 2017 10:50 pm
No new posts Validating file with multiple header/... mohitsaini DFSORT/ICETOOL 6 Thu Apr 13, 2017 1:53 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us