Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2003
    Location
    London
    Posts
    25

    Unanswered: Procedure - for searching & inserting record

    There are two tables , Table A and Table B.

    I need to take the prod_num from table and search for the same in Table B. If prod_num is not found in Table B, then I need to insert the entire
    record into Table B. This needs to be done for all the records..

    If I declare a cursor for the Table A and variable say prod_variable for prod_num for Table B.
    Can I compare values like this ?

    I havent written a single procedure in DB2 so fare . so would like seek your advice ..


    Thank you,

    Regards
    Sbas

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Sbas,
    I think this could be accomplished in a single SQl statement:

    Insert into TableB as B (columns go here) (select columns from A go here from TableA as A where not exists (select * from TableB as B2 where (b2.prodnum = a.prod_num)))

    HTH

    Andy

Posting Permissions

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