Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Results from SUM Function Doubled

Status
Not open for further replies.

madaw

Programmer
Nov 3, 2002
2
CA
I'm using Crystal SQL Designer to create my SQL. This seems to be working, but on some records the result of the SUM function is being doubled - but not all records. I've checked the data and it all looks fine, so I don't quite understand what's going on. Here's my SQL:

SELECT DISTINCT Funeral1.`Codnum`, Funeral1.`Funnum`, Funeral1.`Source`, Funeral1.`Invoiced`, Funeral1.`Dec_Sur`, Funeral1.`Dis_Typ`, Funeral1.`Fun_typ`, Funeral1.`Fun_dir`, Funeral1.`Ser_dat`, Funeral1.`Casketcode`, Sum(IIf(charges1.`category`<>&quot;CREMAT&quot;,charges1.`amount`,0)) AS TOTALSRVC, Sum(IIf(charges1.`category`=&quot;CREMAT&quot;,charges1.`amount`,0)) AS CREMATFEE,
Sum(IIf(merchandise1.`type`=1 AND merchandise1.`number`=Funeral1.`Codnum`,merchandise1.`price`,0)) AS CASKETCOST,
Sum(IIf(merchandise1.`itype`=&quot;U&quot; AND merchandise1.`number`=Funeral1.`Codnum`,merchandise1.`price`,0)) AS URNCOST,
Sum(IIf(merchandise1.`itype`=&quot;V&quot; AND merchandise1.`number`=Funeral1.`Codnum`,merchandise1.`price`,0)) AS OUTERCOST
FROM (`Funeral1` Funeral1 LEFT JOIN `charges1` charges1 ON Funeral1.`Codnum` = charges1.`number`) LEFT JOIN `merchandise1` merchandise1 ON charges1.`number` = merchandise1.`number`
GROUP BY Funeral1.`Codnum`, Funeral1.`Funnum`, Funeral1.`Invoiced`, Funeral1.`Dec_Sur`, Funeral1.`Dis_Typ`, Funeral1.`Fun_typ`, Funeral1.`Fun_dir`, Funeral1.`Ser_dat`


Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top