
~Sum existing values with values from another table
Michael-
All you need to do is add all three comparisons to the respective ON
clauses.
--
John Viescas
author, "Running Microsoft Access 97"
http://www.amazon.com/exec/obidos/ISBN=1572313234/
Quote:
>Thanx for the reply! It worked, but...
>This works great if the primary key is a single field. What would the
>syntax be if the primary key contained 3 fields?
>Many, many TIA
>>Since you need to add values to existing matches, it's best to do this in
>>two steps:
>>Step1:
>>UPDATE TableA INNER JOIN TableB ON (TableA.PKey = TableB.PKey)
>>SET TableA.SomeField = TableA.SomeField + TableB.SomeField;
>>Step2:
>>INSERT INTO TableA
>>SELECT TableB.*
>>FROM TableB LEFT JOIN TableA ON (TableB.PKey = TableA.PKey)
>>WHERE TableA.PKey IS NULL;
>>--
>>John Viescas
>>author, "Running Microsoft Access 97"
>>http://www.amazon.com/exec/obidos/ISBN=1572313234/
>>>I want to add values from one column of table B (obtained by a SELECT
>>query)
>>>to existing values in table A where the primary keys are equal.
>>>Put another way, I usually do an INSERT INTO statement to add the records
>>>from table B (obtained by a SELECT query) into table A. But if records
>>>already exist in table A with the same primary key as the records I want
>to
>>>add from table B, the primary keys will conflict. In this case, I want
to
>>>add the values of one column of the records in table B to the same column
>>>for the corresponding records in table A (with the same primary key).
>>(whew,
>>>I hope that made sense). It's kinda like this: Insert the records from
>>>table B into table A, but if they already exist in table A, then add the
>>>values from table A and table B together.
>>>I can't get any kind of UPDATE query to work. I have also searched
>>DejaNews
>>>with no luck.
>>>Does anyone know how to do this in SQL (or even straight design view)?
>>>Many TIA :-)