All,
I have a query which picks out the final date of the last email sent within my system. The query is as follows:
The basic schematic is:
nonconformance ID and info (from tbllog) + sum of costs (from cost table, can be multiple costs) + last email date sent associated with nonconformance ID (can be multiple emails sent)
The issue I have is that everytime I send a new email (becoming the last sent date) my sum of costs becomes multiplied by the number of email records associated with the same nonconformance ID.
For example:
NCC ID 160 with £500 total cost (2x £250 records) and 3 emails sent
My query outputs that the total cost is £1500.
How can I change my sql to stop this multiplication happening?
I have a query which picks out the final date of the last email sent within my system. The query is as follows:
Code:
SELECT tbllog.NCC_ID, tbllog.DteReport, tbllog.DteOccur, tbldept_1.Department AS DeptRaisedBy, tbldept.Department AS DeptResp, tblstatus.NCStatus, Sum(tblCosts.CostFig) AS SumOfCostFig, Last(tblEmail.EmailDate) AS LastOfEmailDate FROM ((tblstatus INNER JOIN ((tbllog INNER JOIN tbldept AS tbldept_1 ON tbllog.DeptRaisedBy = tbldept_1.DeptID) INNER JOIN tbldept ON tbllog.DeptResp = tbldept.DeptID) ON tblstatus.NCStatusID = tbllog.NCStatus) LEFT JOIN tblCosts ON tbllog.NCC_ID = tblCosts.NCC_ID) LEFT JOIN tblEmail ON tbllog.NCC_ID = tblEmail.NCC_ID1 GROUP BY tbllog.NCC_ID, tbllog.DteReport, tbllog.DteOccur, tbldept_1.Department, tbldept.Department, tblstatus.NCStatus;
nonconformance ID and info (from tbllog) + sum of costs (from cost table, can be multiple costs) + last email date sent associated with nonconformance ID (can be multiple emails sent)
The issue I have is that everytime I send a new email (becoming the last sent date) my sum of costs becomes multiplied by the number of email records associated with the same nonconformance ID.
For example:
NCC ID 160 with £500 total cost (2x £250 records) and 3 emails sent
My query outputs that the total cost is £1500.
How can I change my sql to stop this multiplication happening?
Comment