Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I need help. I have two tabl

Status
Not open for further replies.

guy777

Programmer
Sep 9, 2003
2
0
0
US
Hi,
I need help.
I have two tables A and B both of same structure and type.
I need to insert all the records in A which are not in B(look by primary key). also if i found a match for record in table A with a record in B (based on PK) i need to copy the A record to B record. How can you do this by using cursors by row level updates and inserts..

thanks in advance
 
Guy,

So that I have the proper motivation to write the cursor code, please explain why you must use "cursors by row level updates and inserts" instead of this far simpler code:

Create table_c as
select * from table_a where exists (select 'x' from table_b where table_a.id = table_b.id)
/* ^--- Rows in Table_a that are not in Table_b */
union
select * from table_a where not exists (select 'x' from table_b where table_a.id = table_b.id)
/* ^--- Rows in Table_a with IDs matching Table_b */
union
select * from table_b where not exists (select 'x' from table_a where table_a.id = table_b.id)
/* ^--- Rows in Table_b that are not in Table_a */;

then

drop table_b;
rename table_c to table_b;

Cheers,

Dave
 
Hi Guy,
try this.

inser into b
select * from B
minus
select * from B;

Good luck

Jurandi
 
Hi Guy,
try this.

inser into b
select * from A
minus
select * from B;

Good luck

Jurandi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top