Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2013
    Posts
    11

    Unanswered: conditional insert statement

    Does DB2 support conditional insert statement?

    insert into PRODUCT values ('123', 'PEN', 'a pen') where (select count(*) from PRODUCT < 100) ;

    If not can you please give me the easiest way to achieve this.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I've never seen syntax like that (on any database engine). If it somewhat common in third party tools and languages, but each one has its own syntax.

    Can you describe in English what you want to have happen? I think that we'll have better luck if we "start from scratch" on this problem.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    I'm assuming you just want to insert 99 records into the table PRODUCT. Something like this, may be?
    Code:
    insert into product 
    with tmp (a,b,c, n) as (
     select '123', 'PEN', 'a pen' from sysibm.sysdummy1
     union all
     select a, b, c, n+1 from tmp where n < 99
    ) 
    select a, b, c from tmp
    ---
    "It does not work" is not a valid problem statement.

  4. #4
    Join Date
    Apr 2013
    Posts
    11
    I have an insert trigger on a db2 table, that in turns inserts records in other tables. I wanted to check if DB2 provides a syntax to do an insert on the basis of a complex where clause.
    I am currently exploring the when clause on the trigger to see if this is possible.

    thanks.

  5. #5
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    How about this?
    Code:
    INSERT INTO product
    SELECT '123' , 'PEN' , 'a pen'
     FROM  sysibm.sysdummy1
     WHERE (SELECT COUNT(*)
             FROM  product
           ) < 100
    ;

Tags for this Thread

Posting Permissions

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