AS400 SQL: Update Multiple Field with Value from Fields in another file

Update Multiple Field with Value from Fields in another file

Below Query can update fields a.Fld1,a.Fld2,a.Fld3,a.Fld4 & a.Fld5  in TBL1 with the values from
 b.Bld1 ,b.Bld5,b.Bld3,b.Bld6 & b.Bld8 in TBL2

Below Query will work only if the below query will not have duplicate record
select b.fkey1,b.fkey2 from Tabl2 B, TBL1 a              
where a.fkey1= b.fkey1 and a.fkey2= b.fkey2

If there is duplicate change the where clause to get unique values then use the same whare claues in the subquery in both places


update Tabl1  a set (a.Fld1,a.Fld2,a.Fld3,a.Fld4, a.Fld5  )  =          
(select b.Bld1 ,b.Bld5,b.Bld3,b.Bld6,b.Bld8 from Tabl2 B              
where a.fkey1= b.fkey1 and a.fkey2= b.fkey2 )

Where (fkey1,fkey2) in
(select fkey1,fkey2 from Tbl2)

Comments

Popular posts from this blog

AS400 : Add a new line in text in email SNDSMTPEMM

AS400 Display: Radio Button (SNGCHCFLD)

AS400 Display File: Check Box (MLTCHCFLD)