I am using the following sql query which extracts the companys names from a table and totals the costs in and costs out for that company based on if the case is completed in the current month and is a specific type of case into a gridview. I want the gridview to also display the total cases that were completed for each company.
SELECT Lender.Company, COALESCE (SUM(Commission.AmountIn), 0) AS InCost, COALESCE (SUM(Commission.AmountOut), 0) AS OutCost
FROM Lender INNER JOIN CaseUnderWriting ON Lender.ID = CaseUnderWriting.LenderID INNER JOIN CaseDetails ON CaseUnderWriting.CaseID = CaseDetails.CaseID INNER JOIN CaseProcessing INNER JOIN Commission ON CaseProcessing.CaseID = Commission.CaseID ON CaseDetails.CaseID = Commission.CaseID
WHERE (MONTH(CaseProcessing.StatusDate) = MONTH(GETDATE())) AND (YEAR(CaseProcessing.StatusDate) = YEAR(GETDATE())) AND (CaseProcessing.StatusID = 22) AND (CaseDetails.LoanTypeID = 8)
GROUP BY Lender.Company
ORDER BY Lender.Company