Can anyone identify any problems with this query? The last little piece of my select you can see I'm adding T1.LABOR, T2.PURCHASESTOT, and T3.MOCOST. Everything seems to work great, except for when one of these fields are empty/zero, my total will always be zero. If all fields have a value other than zero, it works just fine. Ideas?
SELECT T1.PROJECT, T1.labhr as LaborHrs, T1.LABOR as LaborCost, T2.PURCHASESTOT as BUYSTOT, T2.PURCHASES as BUYS, T3.MOCOST as MOTOT, T1.LABOR+T2.PURCHASESTOT+T3.MOCOST AS TOT ;
FROM (SELECT project.project, sum(ltxnhist.actlab) AS Labhr, SUM(ltxnhist.actlab*ltxnhist.rate) AS Labor FROM project LEFT OUTER JOIN ltxnhist ON project.project=ltxnhist.project WHERE PROJECT.PROJECT = TAB1.PROJECT GROUP BY project.project) T1;
LEFT JOIN (SELECT project.project, SUM(podet.uprice*podet.qtyord) AS PURCHASESTOT, SUM(podet.uprice*podet.qtyinv) AS Purchases FROM project LEFT OUTER JOIN podet on project.project=podet.project WHERE PROJECT.PROJECT = TAB1.PROJECT GROUP BY project.project) T2;
ON T1.PROJECT=T2.PROJECT;
LEFT JOIN (SELECT project.project, SUM(wpm.fstot*wpm.qtydel) as MOCOST FROM ((project INNER JOIN momast ON project.project=momast.project) INNER JOIN wpm ON momast.mono=wpm.mono) WHERE PROJECT.PROJECT = TAB1.PROJECT GROUP BY project.project) T3;
ON T1.PROJECT=T3.PROJECT;
INTO CURSOR TAB2
FROM (SELECT project.project, sum(ltxnhist.actlab) AS Labhr, SUM(ltxnhist.actlab*ltxnhist.rate) AS Labor FROM project LEFT OUTER JOIN ltxnhist ON project.project=ltxnhist.project WHERE PROJECT.PROJECT = TAB1.PROJECT GROUP BY project.project) T1;
LEFT JOIN (SELECT project.project, SUM(podet.uprice*podet.qtyord) AS PURCHASESTOT, SUM(podet.uprice*podet.qtyinv) AS Purchases FROM project LEFT OUTER JOIN podet on project.project=podet.project WHERE PROJECT.PROJECT = TAB1.PROJECT GROUP BY project.project) T2;
ON T1.PROJECT=T2.PROJECT;
LEFT JOIN (SELECT project.project, SUM(wpm.fstot*wpm.qtydel) as MOCOST FROM ((project INNER JOIN momast ON project.project=momast.project) INNER JOIN wpm ON momast.mono=wpm.mono) WHERE PROJECT.PROJECT = TAB1.PROJECT GROUP BY project.project) T3;
ON T1.PROJECT=T3.PROJECT;
INTO CURSOR TAB2