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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update one table from another 1

Status
Not open for further replies.

kumar7704

Programmer
Feb 13, 2006
3
US

This doesn't work for me on Oracle. Any ideas why it is failing.

I get the following error:
ORA-00933: SQL command not properly ended

I do have the primary key declared on both tables.

Thanks for your help.
 
Hi,
Oracle and SqlServer use very different methods..

For Oracle, try

Update Table1 set (f1,f2,f3) = (select f1,f2,f3 from table2
where table1.key = table2.key);



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
If there are any records in Table1 that are not in Table2, the above statement will set f1, f2, and f3 to null on those records. If this is not the desired behavior, you could try the following:

Update Table1 set (f1,f2,f3) = (
select f1,f2,f3 from table2
where table1.key = table2.key)
Where table1.Key in (Select table2.key From table2);
 
Hi,
Great catch, ddiamond !
I have missed that too many times not to have included it in my code..





[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top