If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Case Statement native sql stored procedure db2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
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.
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,702
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
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 3,224
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;
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Feb 2010
Posts: 8
Thank you...

Hello Tonkuma!!!

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On