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 or if outside query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-22-07, 02:59
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
 
Join Date: Jan 2005
Posts: 75
case or if outside query

Hi is there a way to write case or if clause before running a query. like if a condition is satisfied then update or insert???
Reply With Quote
  #2 (permalink)  
Old 03-22-07, 06:28
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You can use a compound statement:
Code:
BEGIN
   IF <condition> THEN
      <statement>;
   ELSE
      <statement>;
   END IF;
END
If you only worry about insert vs. update, then have a look at the MERGE statement. That gives you the best performance because all the decisions are evaluated internally to DB2 in a more optimized fashion than a procedural approach like above could do.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 03-22-07, 13:26
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Not sure what your actual reqmt is - But check the usage of MERGE statement ... That might help

Sathyaram
__________________
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