Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2010
    Posts
    8

    Question Case Statement native sql stored procedure db2

    Hi All,

    May I ask is this syntax correct for sql native stored procedure?

    CASE sqlcode
    WHEN 0
    THEN
    IF (error_routine = 'true')
    some statement...
    ELSE
    some statement...
    END IF
    WHEN 100
    some statement...
    END CASE
    I am really a beginner in native sql stored procedure in db2. I have many questions . Please bear with me . I can't see complete code examples for this, I don't have any pattern on creating one. I am reading the IBM site. but it is organized as LUW.

    Thank you.

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,734
    The CASE statement is part of a SELECT statement. It does not work the way you have it in your example. Please refer to the SQL Reference Manual.

    However, in a SQL stored procedure, you can use regular IF, THEN, ELSE logic to accomplish what you seem to want to do.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  3. #3
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,479
    CASE statement is a different stuff from CASE expression.

    Your example will work, if you added semicolons at end of each statements, like this...

    CASE sqlcode
    WHEN 0
    THEN
    IF (error_routine = 'true')
    some statement...
    ELSE
    some statement...
    END IF;
    WHEN 100
    THEN
    some statement...
    END CASE;

  4. #4
    Join Date
    Feb 2010
    Posts
    8

    Thank you...

    Hello Tonkuma!!!

    Thank you so much!!!!!! You don't know how grateful I am..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •