CREATE PROC sp__News__NewsPerWeekInYear @Year int AS SELECT DATEPART(WK,DatePosted) AS WeekNumber, COUNT(NewsID) AS NewsPosts FROM News WHERE DATEPART(YYYY, dbo.News.DatePosted) = @Year ORDER BY WeekNumber GO
Returns the error
Msg 8120, Level 16, State 1, Procedure sp__News__NewsPerWeekInYear, Line 5
Column 'News.DatePosted' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
But placing a Group By WeekNumber doesn't seem to help...
I'm a beginner at T-SQL, so excuse me if my error is especially ignorant.