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



... simpelst way would be to use commitment controll:

exec sql Insert into clientfile
select client2, key2, fld3, fld4, ....
from clientfile A
where clientid = :client1;
if sqlcode = 0;
exec sql commit;
else;
exec sql rollback;

Dieter
--------------------------------------------------
From: "David FOXWELL" <David.FOXWELL@xxxxxxxxx>
Sent: Monday, November 15, 2010 9:49 AM
To: "Midrange Systems Technical Discussion" <midrange-l@xxxxxxxxxxxx>
Subject: RE: SQL Duplicate client1 to create client2

Thanks, Charles, Dieter.

But I seem to have gone a bit cold on embedded sql in an rpg program. It's a shame because treating a bunch of records like that seems to be ideal for SQL. What happens when the file changes? The statement protects against duplicates but doesn't indicate to the program that the error occurred.
Using DS records as parameters for the rpg CHAIN and WRITE, I don't have to reference all the fields and I can use our standard error procedure if not the client exists already (%FOUND).

-----Message d'origine-----
De : midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] De la part de Charles Wilt
Envoyé : vendredi 12 novembre 2010 15:46
À : Midrange Systems Technical Discussion
Objet : Re: SQL Duplicate client1 to create client2

Insert into clientfile
select client2, key2, fld3, fld4, ....
from clientfile A
where clientid = client1
and not exists( select * from clientfile B
where b.clientid = client2
and b.key2 = a.key2
)

HTH,
Charles

On Fri, Nov 12, 2010 at 9:15 AM, David FOXWELL
<David.FOXWELL@xxxxxxxxx> wrote:
>
> Can I copy all of client1's records to a new client client2
with SQL?
> Ie, copy all the data but with a different clientId
supplied by my program.
>
> Something like :
>
> Insert into clientfile
> select *from clientfile where clientid = client1 ( but replacing
> client1 with client2)
>
> How should I protect against duplicate records? Normally
the client2 will never exist at this time but you never know!
>
> Thanks.
> --
> 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: http://lists.midrange.com/mailman/listinfo/midrange-l
> or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting,
please take
> a moment to review the archives at
> http://archive.midrange.com/midrange-l.
>
>
--
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: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting,
please take a moment to review the archives at
http://archive.midrange.com/midrange-l.


--
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: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



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.