Msg 147, Level 15, State 1, Procedure vw_OverBudget, Line 10 [Batch Start Line 59]
An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.
Code:
CREATE VIEW vw_OverBudget
AS
SELECT
p.projectName,
SUM(a.costtodate) AS sumActivityCosts,
p.fundedbudget
FROM
Project AS p
FULL OUTER JOIN
Activity a ON p.projectid = a.projectid
WHERE
a.activityId IS NULL
AND p.projectid IS NOT NULL
AND SUM(a.costtodate) > p.fundedbudget
GROUP BY
p.projectID