Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update field from one table with a join table

Status
Not open for further replies.

evr72

MIS
Dec 8, 2009
265
0
0
US
Hello,

I am trying to update a field, I have two join tables.
I have tried a few things but keep on getting various errors

two tables
AMFLIB2.CUSMAS AND AMFLIB2.MBEKRES2
the field I want to update is in AMFLIB2.CUSMAS.ACREC
the where statement uses the field EKCJNB from table AMFLIB2.MBEKRES2
I was wondering if anybody could point me in the right direction
Code:
UPDATE AMFLIB2.CUSMAS                                
SET ACREC = 'S'                                      
WHERE 
LEFT OUTER JOIN AMFLIB2.MBEKRES2
ON AMFLIB2.CUSMAS.CUSNO = AMFLIB2.MBEKRES2.EKCANB 
AND AMFLIB2.MBEKRES2.EKCJNB <1150101

Code:
UPDATE AMFLIB2.CUSMAS                                             
OUTER JOIN AMFLIB2.MBEKRES2 ON AMFLIB2.CUSMAS.CUSNO =             
AMFLIB2.MBEKRES2.EKCANB                                           
SET AMFLIB2.CUSMAS.ACREC = 'S'                                    
FROM AMFLIB2.CUSMAS                                               
WHERE (AMFLIB2.MBEKRES2.EKCJNB <1150101) AND (AMFLIB2.CUSMAS.ACREC
<>'S')
Thanks you
 
Just in case anybody sees this, I figured it out, not pretty but it works

Code:
 UPDATE AMFLIB2.CUSMAS T3                          
    SET T3.ACREC = 'S'                             
    WHERE T3.ACREC IN ('A')                        
      AND EXISTS (                                 
          SELECT                                   
               T1.EKAENB, T1.EKCANB, T1.EKCJNB, T3.
          FROM AMFLIB2.MBEKRES2 T1                 
          WHERE T1.EKCJNB < 1150101 AND T3.CUSNO = 
T3.CUSNO >0 AND T1.EKCJNB<>0 AND   T3.ACREC = 'A')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top