peskyangel
Programmer
I have 5 DB2 tables, all with the same unique primary key.
That key is SEGMENT, CORP and ACCOUNT.
I can have 1 row for a given SEGMENT, CORP and ACCOUNT on all 5 of these tables, or 1 row on 4 of them and not the 5th, 1 row on 3 of them and not the other 2, 1 row on 2 of them and not the other 3, etc. etc.
There might not even be a row on any of the tables for a given SEGMENT, CORP and ACCOUNT.
I am interested in returning the values of two columns from each of these tables.
At the moment, my online COBOL program reads the tables consecutively. If it finds a row on the table, it populates details in a data block. If it doesn't find a row, these details are set to spaces. If there's another SQLCODE the program abends.
I would like to read the tables concurrently.
The SQL I've written to do this is as follows.
SELECT T1.STATUS_TYP, T1.STATUS_START_TS
,T2.STATUS_TYP, T2.STATUS_START_TS
,T3.STATUS_TYP, T3.STATUS_START_TS
,T4.STATUS_TYP, T4.STATUS_START_TS
,T5.STATUS_TYP, T5.STATUS_START_TS
FROM BASSDEV.BRC_DECEASED T1
RIGHT OUTER JOIN BASSDEV.BRC_DEFAULT T2
ON T1.SEGMENT = T2.SEGMENT
AND T1.CORP = T2.CORP
AND T1.ACCOUNT = T2.ACCOUNT
RIGHT OUTER JOIN BASSDEV.BRC_GONE_AWAY T3
ON T1.SEGMENT = T3.SEGMENT
AND T1.CORP = T3.CORP
AND T1.ACCOUNT = T3.ACCOUNT
RIGHT OUTER JOIN BASSDEV.BRC_EXCEPTION T4
ON T1.SEGMENT = T4.SEGMENT
AND T1.CORP = T4.CORP
AND T1.ACCOUNT = T4.ACCOUNT
RIGHT OUTER JOIN BASSDEV.BRC_EXCEPTION T5
ON T1.SEGMENT = T5.SEGMENT
AND T1.CORP = T5.CORP
AND T1.ACCOUNT = T5.ACCOUNT
WHERE (T1.SEGMENT = '01'
AND T1.CORP = '10'
AND T1.ACCOUNT = '4775965306368373')
Now this SQL returns 1 row containing the information I require when SEGMENT '01', CORP '10' and ACCOUNT '4775965306368373' is present on T1, and one, two, three or all four of the other tables.
If the record is not present on T1, nothing is returned, regardless of the fact that the row exists on T2, T3, T4 or T5.
1) Does anyone actually understand what I've just waffled on about? ;-)
2) Can anyone help? I'm pulling my hair out!
Thank you in advance.
That key is SEGMENT, CORP and ACCOUNT.
I can have 1 row for a given SEGMENT, CORP and ACCOUNT on all 5 of these tables, or 1 row on 4 of them and not the 5th, 1 row on 3 of them and not the other 2, 1 row on 2 of them and not the other 3, etc. etc.
There might not even be a row on any of the tables for a given SEGMENT, CORP and ACCOUNT.
I am interested in returning the values of two columns from each of these tables.
At the moment, my online COBOL program reads the tables consecutively. If it finds a row on the table, it populates details in a data block. If it doesn't find a row, these details are set to spaces. If there's another SQLCODE the program abends.
I would like to read the tables concurrently.
The SQL I've written to do this is as follows.
SELECT T1.STATUS_TYP, T1.STATUS_START_TS
,T2.STATUS_TYP, T2.STATUS_START_TS
,T3.STATUS_TYP, T3.STATUS_START_TS
,T4.STATUS_TYP, T4.STATUS_START_TS
,T5.STATUS_TYP, T5.STATUS_START_TS
FROM BASSDEV.BRC_DECEASED T1
RIGHT OUTER JOIN BASSDEV.BRC_DEFAULT T2
ON T1.SEGMENT = T2.SEGMENT
AND T1.CORP = T2.CORP
AND T1.ACCOUNT = T2.ACCOUNT
RIGHT OUTER JOIN BASSDEV.BRC_GONE_AWAY T3
ON T1.SEGMENT = T3.SEGMENT
AND T1.CORP = T3.CORP
AND T1.ACCOUNT = T3.ACCOUNT
RIGHT OUTER JOIN BASSDEV.BRC_EXCEPTION T4
ON T1.SEGMENT = T4.SEGMENT
AND T1.CORP = T4.CORP
AND T1.ACCOUNT = T4.ACCOUNT
RIGHT OUTER JOIN BASSDEV.BRC_EXCEPTION T5
ON T1.SEGMENT = T5.SEGMENT
AND T1.CORP = T5.CORP
AND T1.ACCOUNT = T5.ACCOUNT
WHERE (T1.SEGMENT = '01'
AND T1.CORP = '10'
AND T1.ACCOUNT = '4775965306368373')
Now this SQL returns 1 row containing the information I require when SEGMENT '01', CORP '10' and ACCOUNT '4775965306368373' is present on T1, and one, two, three or all four of the other tables.
If the record is not present on T1, nothing is returned, regardless of the fact that the row exists on T2, T3, T4 or T5.
1) Does anyone actually understand what I've just waffled on about? ;-)
2) Can anyone help? I'm pulling my hair out!
Thank you in advance.