CASE keyword statement in DB2 for IBM iSeries

351865 pts.
Tags:
AS/400
IBM DB2
IBM iSeries
I've been recently writing queries for DB2 on an IBM iSeries box. I know about the "CASE" keyword, but it's not working for me. I keep receiving this error message: Keyword CASE not expected. Here's one of my sample code:
IF EXISTS ( SELECT * FROM MYTABLE WHERE KEY = xxx )
THEN UPDATE MYTABLE SET VALUE = zzz WHERE KEY = xxx
ELSE INSERT INTO MYTABLE (KEY, VALUE) VALUES (xxx, zzz)
END IF
Could someone tell me a way to do this against DB2 on IBM iSeries? I have to run two queries, first a select and then the Java code decides to update/insert. I would rather just write on query. Thanks!

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta

    If that is expected to be a SQL statement sent for processing, I don't see how it could work. If it is the statement that receives the "CASE" error, then DB2 is interpreting it as a CASE structure; and a CASE search-condition cannot include an EXISTS predicate.

    What is the DB2 release? If it's i 7.1, you should use a MERGE statement.

    Tom

    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following