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!

Add a Select 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?
 
Try something like...


insert into Table_Upload (accountid)
select Accountid
from Temp_Acct_Ids

update Table_Upload
set field1 ='Completed',
field2 = 'NA', trunc(sysdate),
field3 = 'This book was read.')
where Accountid in (select Accountid
from Temp_Acct_Ids)


Simi
 
Code:
INSERT INTO Table_Upload 
SELECT Accountid,
       'Completed',
       'NA',
       trunc(sysdate), --- ??????????
       'This book was read.'
from Temp_Acct_Ids


Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top