2
\$\begingroup\$

I have written below SQL in an RPGLE program. Intent is to update the header file (TC400F) if no corresponding records exist in detail file (TC401F). Are there better ways of doing this?

Exec SQL UPDATE TC400F 
 SET T40STS = '05', 
 T40OFL = '1' 
 WHERE T40SID = :K#T41SID AND 
 T40PID = :K#T41PID AND 
 NOT EXISTS (SELECT * FROM TC401F WHERE
 T41SID = :K#T41SID AND 
 T41PID = :K#T41PID ); 
asked Aug 16, 2017 at 16:23
\$\endgroup\$
1

1 Answer 1

1
\$\begingroup\$

Not really but you can simplify your query like this (variable are not replaced 2x)

Exec SQL UPDATE TC400F f1 
 SET (f1.T40STS, f1.T40OFL) = ('05', '1') 
 WHERE (f1.T40SID, f1.T40PID) = (:K#T41SID, :K#T41PID) AND 
 NOT EXISTS
 (SELECT * FROM TC401F f2 WHERE (f1.T40SID, f1.T40PID)=(f2.T41SID, f2.T41PID));
answered Oct 7, 2017 at 19:34
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Did you mean (f2.T40SID, f2.T40PID) or (f2.T41SID, f2.T41PID) in the subselect? \$\endgroup\$ Commented Oct 30, 2017 at 14:17
  • \$\begingroup\$ i have change my query, ty \$\endgroup\$ Commented Oct 30, 2017 at 14:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.