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

Sum Two tables into a third

Status
Not open for further replies.

ynnepztem

Programmer
Aug 2, 2001
54
US
I have three tables

Table 1
Language
Pending
Age

Table 2
Language
Pending

Table 3
Language
Pending
Age

I want to write everything from Table 1 into Table 3 and where the Language is the same, add the Pending from Table 2 to Table 3.

Any help once again is greatly appreciated.

I am using SQL Server 200 and VB6
 
I'm not sure I completely understand the aim here but is this something near what you need?

Code:
INSERT table3
SELECT language, pending, age
FROM table1

INSERT table3 (language, pending)
SELECT language, pending
FROM table2
WHERE language IN (SELECT language FROM table1)
--James
 
Are you saying you want to INSERT everything from table1 into table3 and add[as in sum] the "pending" column VALUES in table2 to the "pending " column in table3 where the language is the same?

If so:

INSERT table3
SELECT language, pending, age
FROM table1

update table3 set pending=pending+(select sum(pending) from table2 where language=A.language)
 
Sorry for the incomplete reply. Here is what i meant to say:

Are you saying you want to INSERT everything from table1 into table3 and add[as in sum] the "pending" column VALUES in table2 to the "pending " column in table3 where the language is the same?

If so:

INSERT table3 (language,pending,age)
select language,
pending+ (select sum(pending) from table2
where language=A.language)
from table1 A
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top