Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 6968
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: 6968
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: 1281
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: 6968
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 Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Partial color change of a field in CI... waseem0424 CICS 5 Fri Sep 29, 2017 7:56 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us