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



you don't even need the select * part of that as you can simply use the
values expression.

USING (values (9300000022, 1)) b2 (manifest, cnt)

The other way I have done this, mostly when I have an array of data that I
want to merge into a table, is to create a temporary table with DECLARE
GLOBAL TEMPORARY TABLE. You can use INSERT to load an array of data into a
table, but you cannot use the array in a MERGE statement. Then I use the
temporary table to do the merge. Once I am done with the temporary table, I
drop it.

On Thu, Oct 26, 2017 at 4:23 PM, <dlclark@xxxxxxxxxxxxxxxx> wrote:

"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
--
int.ext: 91078
direct: (937) 531-6378
home: (937) 751-3300

Winsupply Group Services
3110 Kettering Boulevard
Dayton, Ohio 45439 USA
(937) 294-5331




************************************************************
*********************************
This email message and any attachments is for use only by the named
addressee(s) and may contain confidential, privileged and/or proprietary
information. If you have received this message in error, please
immediately notify the sender and delete and destroy the message and all
copies. All unauthorized direct or indirect use or disclosure of this
message is strictly prohibited. No right to confidentiality or privilege
is waived or lost by any error in transmission.
************************************************************
*********************************
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD


As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.