I can handle joins when there are only 2 files involved, but I'm not sure what to do when I need to use 3 files.
Using the code below, my problem is that I'm not getting records when T1.TRF05 is blank because it doesn't have a matching record in T2. I need some data fields from T1 and T2. T3 is a security file to make sure that the user has security to view data in T1.
I've tried using a LEFT JOIN, but keep getting error messages since I'm not sure how to reference T3. Any help would be greatly appreciated.
Using the code below, my problem is that I'm not getting records when T1.TRF05 is blank because it doesn't have a matching record in T2. I need some data fields from T1 and T2. T3 is a security file to make sure that the user has security to view data in T1.
I've tried using a LEFT JOIN, but keep getting error messages since I'm not sure how to reference T3. Any help would be greatly appreciated.
Code:
SELECT
T1.TCONO,
T1.TDVNO,
SUM(T1.TAMGL),
T2.CNM25,
T1.TRF05
from
JCPPST T1,
CSTMST T2,
SECBI T3
WHERE
( T1.TCONO=T2.CCONO and T1.TDVNO=T2.CDVNO and T1.TRF05=T2.CCUST)
AND
( T1.TCONO=T3.BICONO and T1.TDVNO=T3.BIDVNO and T3.BIA01D='Y' OR
T3.BICONO=0 and T3.BIDVNO=0 and T3.BIA01D='Y' OR
T3.BICONO=0 and T1.TDVNO=T3.BIDVNO and T3.BIA01D='Y' OR
T1.TCONO=T3.BICONO and T3.BIDVNO=0 and T3.BIA01D='Y')
AND
( T3.BIUSER=@Variable('BOUSER') )
AND (T1.TCONO in (1,2,3, 7)
AND T1.TDVNO = 0
AND T1.TCSTY = 'I'
AND T1.TDTEN between @variable('1. Start Date (YYYYMMDD)') and @variable('2. End Date (YYYYMMDD)') )
GROUP BY T1.TCONO, T1.TDVNO, T1.TRF05, T2.CNM25