sk1hotpepr
Technical User
I wrote this code to sum four fields based on the ContractorID grouping (there's a left join to get Contractor info from a different table and list the contract price even if there are no change orders). When I run the procedure, I'm getting the overall sum for the project number, not grouped. Can anyone figure out what I'm coding wrong here? Any help is appreciated.
Thanks,
Sherry
Thanks,
Sherry
Code:
ALTER PROCEDURE dbo.spBudget
(@pnum nvarchar(50))
AS SELECT PC.Firm, PC.ActBid,
(SUM(CASE when (CT.ApprovedCost IS NOT NULL) THEN CT.ApprovedCost ELSE 0 END)) AS AppCst,
(SUM(CASE when (CT.GACost IS NOT NULL) THEN CT.GACost ELSE 0 END)) AS GAC,
(SUM(CASE when (CT.SDCost IS NOT NULL) THEN CT.SDCost ELSE 0 END)) AS SDC,
(SUM(CASE when (CT.PropCost IS NOT NULL) THEN CT.PropCost ELSE 0 END)) AS Prop,
PI.ProjectName, IDC.ContractorIDDescription, PC.ProjectNumber, PC.CID
FROM dbo.ChangeOrderTable CT RIGHT OUTER JOIN dbo.ProjectContractor PC ON CT.ProjectNumber = PC.ProjectNumber INNER JOIN
dbo.ProjectInformation PI ON PC.ProjectNumber = PI.ProjectNumber INNER JOIN
dbo.IDContractor IDC ON PC.CID = IDC.ContractorID
WHERE PC.ProjectNumber = @pnum
GROUP BY PC.Firm, PC.CID, PC.ActBid, PC.ProjectNumber, PI.ProjectName, IDC.ContractorIDDescription