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
 

 

Update query to update one field for two different condition

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
sandip_mainframe
Warnings : 2

New User


Joined: 20 Sep 2006
Posts: 61
Location: pune

PostPosted: Thu Dec 17, 2009 4:23 pm    Post subject: Update query to update one field for two different condition
Reply with quote

Hi All,
My requirement is that I need to Update one field for two different condtions.

UPDATE TABLE
SET REQ_STA_CD = '6'
WHERE ENROLL_TYPE = 'R'

UPDATE TABLE
SET REQ_STA_CD = '7'
WHERE ENROLL_TYPE = 'V'

Is it possible to Update it in a single query ? If it is Please provide me the query.

Thanks,
Sandip Walsinge
Back to top
View user's profile Send private message

belchoff

New User


Joined: 21 Oct 2009
Posts: 4
Location: UK

PostPosted: Thu Dec 17, 2009 4:40 pm    Post subject:
Reply with quote

Have you heard about IN clause?

check it pls (google / manuals).
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Thu Dec 17, 2009 4:42 pm    Post subject:
Reply with quote

Sandip,
You can do it in the following way.

Code:
UPDATE TABLE
SET REQ_STA_CD = (CASE WHEN ENROLL_TYPE = 'R' THEN '6'
             WHEN ENROLL_TYPE = 'V' THEN '7' END) 
WHERE ENROLL_TYPE = 'R' OR ENROLL_TYPE = 'V';
Back to top
View user's profile Send private message
rexx77

New User


Joined: 14 Apr 2008
Posts: 74
Location: Mysore

PostPosted: Thu Dec 17, 2009 4:44 pm    Post subject:
Reply with quote

AFAIK, there is no single query to perform your requirement.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Thu Dec 17, 2009 4:51 pm    Post subject:
Reply with quote

Code:

UPDATE TABLE A
SET REQ_STA_CD = ( SELECT CASE WHEN ENROLL_TYPE = 'R' THEN '6'
                                                      WHEN ENROLL_TYPE = 'V' THEN '7'
                                 END FROM TABLE WHERE COL =   A.COL       )


This is possible only if there is a unique column COL in this table or else the inner query will receive -811.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Thu Dec 17, 2009 4:54 pm    Post subject:
Reply with quote

Good one Srihari.
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
This topic is locked: you cannot edit posts or make replies. Need help on If condition continuatio... ashok_uddaraju CLIST & REXX 4 Fri May 19, 2017 8:55 am
No new posts Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 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
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts Alter &DATENS field in HEADER1 Angad DFSORT/ICETOOL 4 Mon Apr 24, 2017 11:49 am


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