【发布时间】:2009-05-19 12:58:38
【问题描述】:
已解决。该语句位于存储过程的另一部分。
我正在编写的存储过程不允许我这样做:
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
给我这个错误:
列“database..table.date_build”是 在 ORDER BY 子句中无效,因为 它不包含在任何一个 聚合函数或 GROUP BY 子句。
我做错了什么?
[编辑] 这里没有 group by 语句。 SQL2005.
这里有更多上下文:
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
【问题讨论】:
-
能否把表定义、@Parent 和@Child 的内容,以及您使用的数据库软件贴出来?
-
所以你的语句中没有 GROUP BY 子句?你确定吗?
-
我注意到您同时拥有@dtTopDate 和@dtLatestDate。这是故意的吗?
-
那里的声明不正确。当前的编辑是正确的。
-
能贴出整个存储过程吗?看起来在此之前或之后有一些东西会导致错误。
标签: sql