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

Update the Row which is selected - Cobol Db2 pgm ..


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sreelu.s

New User


Joined: 23 Jul 2010
Posts: 10
Location: hyderabad

PostPosted: Sun Jul 15, 2012 3:41 pm
Reply with quote

Hello ,

I have a Client Address (CAD) Table with columns :
Client_no, Ad_type_cd,Str1,Str2,St_cd,Pin_cd ..... Suppose I have the AD_type values as 'HMM','OTH','RES' and so on ..

NOTE : Client number is not unique. For one client number I can get all the address type rows ....

I have to sort the rows with the first preference as hmm for a Client .Even If hmm is not found then which ever comes first should be taken and that particular row shud be updated (multiple columns but not client_no, Ad_type )

Select Client_no, Str1,Str2 , (Case Ad_type When 'HMM' 0 else 1 End) as Sort1 from CAD Where client _no = Ws:client_no Order by Sort1
Fetch First Row only ;

If Sqlcode = 0
Perform Update_para.

I am not sure how to write the update para for the row selected in the above statement.

Please Suggest me If I can do the same with in a Single Query ( may be with subquery or Where Exists .. What ever )
Thanks in Advance .....
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Mon Jul 16, 2012 2:01 am
Reply with quote

Hello,

Post some sample rows that demonstrate the possible combinations of the data and how you want your process to work. The better samples you post, the more likely you are to get a usable reply.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Jul 16, 2012 12:15 pm
Reply with quote

in the assumption that Client_no,ad_type is a unique key :
Code:
update CAD A
set ...
where A.Client_no = :Ws-client-no
and A.Ad_type in
(
Select B.ad_type from CAD B Where B.client _no = A.Client_no
Order by  Case When B.Ad_type = 'HMM' then 0 else 1 End
Fetch First Row only 
)
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts IBM IMU Utility for Easytrieve Code t... IBM Tools 0
No new posts Big Five Personality Test in COBOL - ... COBOL Programming 0
No new posts I wrote a Hallmark Movie Plot Generat... COBOL Programming 0
No new posts COBOL Text Adventure Engine for TK4- ... COBOL Programming 0
No new posts Cobcalc: An Algebraic Expression Eval... COBOL Programming 10
Search our Forums:


Back to Top