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!

Add a Select statement to a Insert statement

Status
Not open for further replies.

jasonhuibers

Programmer
Sep 12, 2005
290
CA
I have a temp table (Temp_Acct_Ids) with a list of account ids.


For each account in the temp table I need to add a comment in another table for each record:

INSERT INTO Table_Upload VALUES(XXXXXX, 'Completed', 'NA', trunc(sysdate), 'This book was read.');


How can I replace XXXXXX in the insert statement with an Account id from Temp_Acct_Ids? If there are 50 accounts in
Temp_Acct_Ids... Then I need to have 50 records INSERTED into the Table_Upload..

How can I do this?
 
Hi,
Its been a while but try:
Code:
Insert into Table_Upload 
Select Temp_Acct_Ids,'Completed','NA','This book was read'
from
Temp_Acct_Ids;

Not sure if you need to add the list of fields in the Table_Upload
table after the table name in the Insert Into statement.



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Just a slight correction to Turkbear's excellent suggestion (since the DATE column is missing in the code):
Code:
Insert into Table_Upload 
       Select Temp_Acct_Ids
             ,'Completed'
             ,'NA'
             ,[b]trunc(sysdate)[/b]
             ,'This book was read'
  from Temp_Acct_Ids;
TurkBear said:
Not sure if you need to add the list of fields in the Table_Upload table after the table name in the Insert Into statement.
The INSERT statement does not need the column list if the TABLE_UPLOAD has five columns where Col 1 is NUMBER or VARCHAR2, Col 2 is VARCHAR2, Col 3 is VARCHAR2, Col 4 is DATE, and Col 5 is VARCHAR2 data types.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
“People may forget what you say, but they will never forget how you made them feel.
 
Thanks Santa for correcting my oversight....


(I'm glad I remembered the technique, its now been 4+ years since I worked with Oracle ( or worked at all) ) - Retirement Rocks!




[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