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 > db2 sql stored procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-04, 14:19
nic39 nic39 is offline
Registered User
 
Join Date: Jan 2004
Posts: 10
db2 sql stored procedure

Is there a way to add conditional logic in sql stored procedures
I want to say
if(my query return no rows) then
do this;
else
do other;

Thanks for any info
Reply With Quote
  #2 (permalink)  
Old 10-13-04, 15:16
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I think one of the ways to accomplish this would be
Code:
IF EXISTS (SELECT ... FROM ... WHERE ...) THEN...
Reply With Quote
  #3 (permalink)  
Old 10-19-04, 02:20
vidyaraok vidyaraok is offline
Registered User
 
Join Date: Aug 2004
Posts: 15
can use

get diagnostic cnt = row_count;
if cnt = 0 then
...

..
Reply With Quote
  #4 (permalink)  
Old 10-19-04, 03:58
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
This may not be the best way to do existence checking ...

Cheers
sathyaram

Quote:
Originally Posted by vidyaraok
can use

get diagnostic cnt = row_count;
if cnt = 0 then
...

..
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
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