Subject Inserting with a select
Author Tim Ledgerwood
Hi all,

I have a table I am using to reconcile client transactions. One of the
fields in this table is "BATCHNO" - all transactions are allocated a batch
number when they are generated.

I have 6 different types of transactions I need to reconcile. The first
type has been very easy to insert :

"INSERT INTO RECON (field1, field2, field3)
SELECT fieldA, fieldB, SUM(FieldC)
FROM Table2
WHERE fieldA = 'xyz'
GROUP BY fieldA, fieldB"

Now I need to populate the other fields in the RECON table. Some rows will
not have values - for some batches, there will be no transactions that fit
the criteria.

So how do I make sure that the fields are updated matching the batch
numbers? I think I need to do some kind of double select, but am not sure -

"INSERT INTO RECON (field1, field2, field3)

SELECT fieldA, fieldB, SUM(FieldC)
FROM Table2
WHERE fieldA = 'xyz'
GROUP BY fieldA, fieldB

WHERE Table2.BATCHNO = RECON.BATCHNO"

??? Anyone got any idea of how I can do this?

There are only 2 tables - RECON is effectively a summary of the data in Table2.

Thanks in advance,

Tim




[Non-text portions of this message have been removed]