If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
At the end of a function, I want to ensure that there is a
Table_B record for each Table_A record. IE Find items for the
col_a,col_b,col_c on Table_A that are not in Table_B.
If a corresponding Table_B row doesn't exist, it should be created.
The Table_B records created will have col_d = to the sum of
Table_A.col_e. How can I do this?
Location: The extremely Royal borough of Kensington, London
Posts: 778
insert into table_B
select A.col_a, A.col_b, A.col_c,
sum(A.col_a+A.col_b+A.col_c+A.col_d+A.col_e)
from table_A A
LEFT OUTER JOIN
table_B B ON
A.col_a = B.col_a AND
A.col_b = B.col_b AND
A.col_c = B.col_c
where B.col_a is null
group by A.col_a, A.col_b, A.col_c;
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.