Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    80

    Unanswered: 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???

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

  3. #3
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    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.

Posting Permissions

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