"MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxx> wrote on 10/26/2017
03:36:33 PM:
Thanks Dave. You're right, I was trying to do a
chain
if not found
write
else
update
endif
I don't have another table. I'm modifying a program that writes out to
the
table to send as a CSV.
I changed the table to have a primary key and did the RPG to check.
Basically, the MERGE is intended to be presented with a secondary
list of rows to be merged into the primary table. In your case, you have
no secondary list because you selected a row by key from the primary table
that does not exist. That isn't a NOT MATCHED condition. There has to be
an actual row in the secondary list that does not match any row in the
primary list. So, you just need to create a row in the secondary list
that contains the data to be either inserted or updated in the primary
list. Then, your MERGE will work as you want it to.
If all you have are standalone values (no related table of
values), then you can still do that using the TABLE constructor suggested
by Charles. Note that the X, in this case, becomes the name of the
temporary table constructed and the list following that are the temporary
column names -- which you can reference later, as shown below (not
tested).
MERGE INTO BOXDETWK as b1
USING ( SELECT *
from TABLE ( VALUES (93000022, 1)
) X (manifest, cnt)
) as b2
ON b1.manifest = b2.manifest
WHEN MATCHED THEN
UPDATE SET b1.cnt = b1.cnt + b2.cnt
WHEN NOT MATCHED THEN
INSERT (manifest, cnt) VALUES (b2.manifest, b2.cnt)
Sincerely,
Dave Clark
As an Amazon Associate we earn from qualifying purchases.