× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



"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.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.