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



Thanks Joe. That did it.

I was thinking about the "not exists" option before but not in combination with the exists. That combo was the trick.

Pete


Joe Pluta wrote:
From: Pete Helgren

update FileA a set a.date = 070810
where exists
(select b.job,b.ssn from ppay408b b where a.job=b.job and
a.ssn = b.ssn and a.date <> 070810)

I ended up with an error about a duplicate record in FileA (presumably
because the FileA record with | 0023 | Fodserv| 070728 would be
updated to | 0023 | Fodserv| 070810 which already exists. So the
question is: How do I omit records that could potentially become
duplicates? In the case above, the SQL would attempt to update the
first two records since they did not have a date value of 070810.

The straightforward way is to do pretty much do exactly what you said, noly
express it in SQL:

update FileA a set a.date = 070810
where exists
(select 1 from ppay408b b where a.job=b.job and
a.ssn = b.ssn and a.date <> 070810)
and not exists
(select 1 from FileA a2 where a2.job=a.job and
a2.ssn = a.ssn and a2.date = 070810)

The second clause sees if any records with the target date exist in FileA
before attempting the update. Note I did the "select 1" technique rather
than "select b.job,b.ssn" because in an existence check you don't care about
columns, just whether a row exists or not.

Disclaimer: I did NOT test this statement! But it seems pretty reasonable.


The follow up question is: Is there a way to update both files at once?

I can't imagine a way to do it except maybe with commitment control. If
you're worried about an atomic update (that is, being sure nothing sneaks in
between your two SQL statements), then an easy answer would be to issue an
ALCOBJ *EXCL on both files before starting the SQL statements.

Joe




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.