This was resolved. The statement was in another part of the stored procedure.
The stored procedure I’m writing won’t allow me to do this:
declare @dtTopDate datetime
select top 1 @dtTopDate = date_build
from database..table
where database..table.parent = @Parent
and database..table.child = @Child
order by date_build desc
Gives me this error:
Column “database..table.date_build” is
invalid in the ORDER BY clause because
it is not contained in either an
aggregate function or the GROUP BY
clause.
What am I doing wrong?
[Edit] There is no group by statement here. SQL2005.
Here is some more context:
if @Notify = 0
begin
declare @dtTopDate datetime
select top 1 @dtTopDate = date_build
from database..table
where database..table.parent = @Parent
and database..table.child = @Child
order by date_build desc
insert
into database2..table
(parent, child, notification_date, change_date)
values (@Parent, @Child, @dtTopDate, getdate())
return
end
The problem was in another part of the stored procedure. I was using a count(*) elsewhere and it required a group by. Thanks for the help.