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 > Procedure - for searching & inserting record

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-27-04, 05:53
sbas sbas is offline
Registered User
 
Join Date: Aug 2003
Location: London
Posts: 25
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
Reply With Quote
  #2 (permalink)  
Old 04-27-04, 10:10
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
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
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