Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012
    Posts
    8

    Unanswered: Insert into multiple table from single select in DB2

    Hi Guys,

    I want to insert data into two tables using select data from one table.

    example

    INSERT INTO TAB1(ROLL,NAME) SELECT ROLL,NAME FROM STUD;
    INSERT INTO TAB2(ROLL,REG_NAME) SELECT ROLL,NAME FROM STUD;

    I want this in a single select like-

    INSERT INTO TAB1(ROLL,NAME) ,TAB2(ROLL,NAME) SELECT ROLL,NAME FROM STUD;

    Any help?

    Thnx in advance.
    Pravin Dwiwedi

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Try...

    Code:
    WITH
     insert_1 AS (
    SELECT roll , name
     FROM  FINAL TABLE
          (INSERT INTO test_multi_insert.tab1
           SELECT roll , name
            FROM  test_multi_insert.stud
          )
    )
    SELECT roll , reg_name
     FROM  FINAL TABLE
          (INSERT INTO test_multi_insert.tab2
           SELECT roll , name
            FROM  insert_1
          )
    ;
    Last edited by tonkuma; 08-03-12 at 07:47. Reason: Replace table names.

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
  •