I am writing an application which calculates profit from 3 column values. The SQL is as follows in vb dataset designer;
SELECT ID, Sale - (Weight * 20) * (Rate -5) AS Profit
From AgencyRegister
WHERE (DatePart('yyyy', ArrivalDate) = ?)
ORDER BY ArrivalDate
I want to add another column of 'Total' that may display running profit an a separate column. I've tried;
SELECT a.ID, a.Sale - (a.Rate - 5) * (a.Weight * 20) AS Profit, SUM(b.Sale - (b.Rate - 5) * (b.Weight * 20)) AS Total
FROM AgencyRegister a, AgencyRegister b
WHERE (DatePart('yyyy', a.ArrivalDate) = ?) AND a.ID = b.ID
ORDER BY a.ArrivalDate
But vb SQL designer automatically converts it to
SELECT a.ID, a.Sale - (a.Rate - 5) * (a.Weight * 20) AS Profit, SUM(b.Sale - (b.Rate - 5) * (b.Weight * 20)) AS Total
FROM (AgencyRegister a INNER JOIN
AgencyRegister b ON a.ID = b.ID)
WHERE (DatePart('yyyy', a.ArrivalDate) = ?)
ORDER BY a.ArrivalDate
But this code does not run and displays an error.
Please suggest me how do i fix it.