IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Partial column update while using UPDATE with CASE


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts first column truncated in search result IBM Tools 13
No new posts Zunit Test case editor error Testing & Performance 4
Search our Forums:

Back to Top