MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Updating Rows From Joined Tables

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
ciberc
Beginner


Joined: 16 Sep 2003
Posts: 3
Topics: 2

PostPosted: Tue Sep 16, 2003 7:17 am    Post subject: Updating Rows From Joined Tables Reply with quote

I would like to join TBL_A with TBL_B with two common keys between both tables. For all rows from the result set, I would like to update FLD_A of TBL_A with the value of FLD_B on the same table. I was suggested for the SQL below. However, this solution applies only to DB2 V7 and my shop is using V6 (I did try but failed for 'SQLCODE = -104, ERROR: ILLEGAL SYMBOL ","'). Could anyone suggest what can I do?

UPDATE TBL_A
SET FLD_A = FLD_B
WHERE (KEY_A, KEY_B)
IN (SELECT A.KEY_A, A.KEY_B
FROM TBL_A A
,TBL_B B
WHERE A.KEY_A = KEY_A
AND A.KEY_B = B.KEY_B
AND B.KEY_C = 22)
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Sep 16, 2003 8:00 am    Post subject: Reply with quote

Ciberc,

Try this

Code:

UPDATE TBL_A
   SET FLD_A =  FLD_B
WHERE KEY_A IN  (SELECT KEY_A
                        FROM
                        TBL_B 
                        WHERE KEY_C = 22)
  AND KEY_B IN (SELECT KEY_B
                        FROM
                        TBL_B 
                        WHERE KEY_C = 22)



Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group