Home DADE

Confusion over linking tables

edited September 2003 in DADE
I have the following 2 linked dataviews.

A copy and paste from the Master is as follows

SELECT DISTINCT CCR_1.CUSTNO, CCR_1.CONTRACTNO,
CCR_1.SALESMANAGER, CCR_1.SOLDBY,
CCR_1.CONTRACTTYPE, CCR_1.NAME,
CCR_1.FINANCEVALUE,
CCR_1.PAYMENTMETHOD,
CCR_1.LEADNO, CCR_1.LEADSOURCE,
CCR_1.SUBSOURCE, CCR_1.FINCONAME,
CCR_1.FINANCEPPP,
CCR_1.FINANCETERM,
CCR_1.FINANCERATE,
CCR_1.SUPPLYONLY, CCR_1.SALESAREA
FROM CCR CCR_1 INNER JOIN CCRACC CCRACC_1 ON
(CCRACC_1.CUSTNO = CCR_1.CUSTNO)
AND (CCRACC_1.CONTRACTNO = CCR_1.CONTRACTNO)
WHERE
( CCRACC_1."DATE" BETWEEN '09/01/2003' AND '09/30/2003' )
ORDER BY CCR_1.SALESMANAGER, CCR_1.SOLDBY,
CCR_1.CONTRACTTYPE, CCR_1.CUSTNO,
CCR_1.CONTRACTNO


and from the Detail is

SELECT CCRACC_1.CUSTNO, CCRACC_1.CONTRACTNO,
SUM(CCRACC_1.AMOUNTCHARGED) SUM_CCRACC_1_AMOUNTCHARGE
FROM CCRACC CCRACC_1
WHERE
( CCRACC_1."DATE" BETWEEN '09/01/2003' AND '09/30/2003' )
AND (( CCRACC_1.DETAILS LIKE '02%' )
OR ( CCRACC_1.DETAILS LIKE '03%' )
OR ( CCRACC_1.DETAILS LIKE '04%' )
OR ( CCRACC_1.DETAILS LIKE '05%' ))
GROUP BY CCRACC_1.CUSTNO, CCRACC_1.CONTRACTNO

I have linked the detail to the master on CUSTNO,CONTRACTNO as these are the
key fields.

If I dont link them my SUM of the amount charged field is correct. When I
do link them I get a SUM many times multiplied what it should be.

I think I may have misunderstood something basic here about linking so if
you could help me sort it out I would be most grateful.

There is in fact several details that pick up totals for different entries
in the Details field which is why this isn't all in one query.

TIA
Rhonda Ridge
This discussion has been closed.