Subject Re: [ib-support] selecting max date
Author Helen Borrie
At 12:46 PM 20-12-00 +0000, you wrote:
>Hello,
>
>
>I have a query that I would like to return only one row. The primary
>key on the table is the object_id, blob_type_id and the object_date
>(the date the item was entered in the table). I have SQL like:
>
>select object_date, object_sc from object_blob where object_id
>= :object_id and blob_type_id = 7 and object_date = max(object_date)
>
>I get "Invalid aggregate reference" from the above statement. How
>can I do this?
>

You will have to do it in a stored procedure, something like

create procedure GetStuff (ID integer, b_type integer)
returns (o_date date, o_sc varchar(whatever))
as
begin
select max(object_date) from object_blob
where object_id = :ID and blob_type = :b_type
into :o_date;
select object_sc from object_blob
where object_id = :ID and blob_type = :b_type and object_date = :o_date
into :o_sc;
suspend;
end

Helen


All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________