sql - Update table with Left Join -
how update table left join on script. i'm using db2 database.
i created select statement , works:
**
select t1.estrcd "transaction code", t1.espyno "payer", t1.escuno "customer no", t1.escino "invoice no", t1.esvono "voucher no", t1.escuam "foreign currency amount", coalesce(t2."received_amount",0) "received amount", t1.escuam + coalesce(t2."received_amount",0) "outstanding amount" m3edbedu.fsledg t1 left join (select espyno, escino, sum(escuam) "received_amount" m3edbedu.fsledg estrcd = 20 group espyno, escino) t2 on t2.espyno = t1.espyno , t2.escino = t1.escino t1.esreco = 0 , t1.estrcd = 10 , (t1.escuam + coalesce(t2."received_amount",0)) = 0 order t1.espyno, t1.escino, t1.estrcd;
**
but ask me update table , set t1.esreco 9. tried using below script update i'm getting error.
update m3edbedu.fsledg t1 left join(select espyno, escino, sum(escuam) "received_amount" m3edbedu.fsledg estrcd = 20 group espyno, escino) t2 on t2.espyno = t1.espyno , t2.escino = t1.escino set t1.esreco = 9 t1.esreco = 0 , t1.estrcd = 10 , (t1.escuam + coalesce(t2."received_amount",0)) = 0 order t1.espyno, t1.escino, t1.estrcd;1;
error: sql0199 - keyword left not expected. valid tokens: set. (state:37000, native code: ffffff39) error: sql0104 - token 1 not valid. valid tokens: ( cl end set call drop free hold lock open alter begin. (state:37000, native code: ffffff98)
i hope can me.
thanks in advance. :)
since db2 database, cannot specify clause in update statement. updated answer reflect you'd have (keep in mind in no way optimized).
update m3edbedu.fsledg t1 set t1.esreco = 9 t1.esreco = 0 , t1.estrcd = 10 , exists(select t2.espyno m3edbedu.fsledg t2 t2.estrcd = 20 , t2.espyno = t1.espyno , t2.escino = t1.escino) , (t1.escuam + coalesce( (select sum(t2.escuam) m3edbedu.fsledg t2 t2.estrcd = 20 , t2.espyno = t1.espyno , t2.escino = t1.escino), 0) = 0)
Comments
Post a Comment