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
 

 

Partial column update while using UPDATE with CASE

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Jeya Raj

New User


Joined: 14 Jan 2007
Posts: 33
Location: USA

PostPosted: Mon May 21, 2012 11:38 pm    Post subject: Partial column update while using UPDATE with CASE
Reply with quote

Hello,

Could you please let me know is it posible to do a paritial column update when using UPDATE with CASE statement like below?

UPDATE A SET C1(1:2) =

CASE
WHEN C2 = 'CSE' AND C1(1:1) = '1' THEN '01'
WHEN C2 = 'CSE' AND C1(1:1) = '2' THEN '02'
END ;

Thank you.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue May 22, 2012 1:09 am    Post subject:
Reply with quote

you can, but your syntax is wrong:

UPDATE A SET C1 =
WHEN C2 = 'CSE' AND C1(1:1) = '1' THEN '01' || RIGHT(C1, LENGTH(C1) - 2,OCTETS)
WHEN C2 = 'CSE' AND C1(1:1) = '2' THEN '02' || RIGHT(C1, LENGTH(C1) - 2,OCTETS)
ELSE C1
END


When using CASE expressions, besure to have an ELSE for those rows that are not true for any of the WHENs.
you should add:
ELSE C1
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue May 22, 2012 1:17 am    Post subject:
Reply with quote

the above only works if the length of column C1 is > 2.

hopefully it is some variation of CHAR.
will not work for a numeric or date/time column.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Tue May 22, 2012 4:49 pm    Post subject:
Reply with quote

C1(1:1) ? this is SQL, not cobol

try
Code:
case when substr(C1,1,1)  in ('1','2') then  '0' || substr(name,1,1)  || substr(name,3)  else C1 end
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue May 22, 2012 5:11 pm    Post subject:
Reply with quote

ah well my syntax was not much better. icon_redface.gif
Back to top
View user's profile Send private message
Jeya Raj

New User


Joined: 14 Jan 2007
Posts: 33
Location: USA

PostPosted: Tue May 22, 2012 6:26 pm    Post subject:
Reply with quote

Thank you gentlemen. It worked very well. I really appriciate your help!!!
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 Summing on Mixed Case Literals Roy Ware SYNCSORT 3 Tue Jan 03, 2017 10:18 pm
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts -913/-911 Deadlock during UPDATE stat... NoSleep319 DB2 5 Fri Nov 18, 2016 12:37 am
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts Updating Cursor row withour using FOR... chandan.inst DB2 15 Tue Nov 08, 2016 11:17 am


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