|
Updating the value of a column within a row in one table from a
value obtained from a related row, or group of rows, from another
table was not added until V4R3.
Are you running V4R3? With V4R3 I am able to do the following:
CREATE TABLE ROB/HEADER (KEYFIELD DEC (7, 0) NOT NULL WITH DEFAULT,
COUNTDTL DEC (7, 0) NOT NULL WITH DEFAULT)
INSERT INTO ROB/HEADER VALUES(1, 0)
INSERT INTO ROB/HEADER VALUES(2, 0)
CREATE TABLE ROB/DETAIL (KEYFIELD DEC (7, 0) NOT NULL WITH DEFAULT,
LINEKEY DEC (7, 0) NOT NULL WITH DEFAULT)
INSERT INTO ROB/DETAIL VALUES(1, 1)
INSERT INTO ROB/DETAIL VALUES(1, 2)
INSERT INTO ROB/DETAIL VALUES(1, 3)
INSERT INTO ROB/DETAIL VALUES(2, 1)
INSERT INTO ROB/DETAIL VALUES(2, 2)
update rob/header
set countdtl = (select count(*)
from rob/detail
where header.keyfield = detail.keyfield)
select * from rob/header
And I'll see:
KEYFIELD COUNTDTL
1 3
2 2
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.