Subject Re: The Last Record.......in Selects
Author henry FRANQUET
--- In ib-support@yahoogroups.com, "Fernando Buitrago \(Listas y
Foros\)" <buitragon@h...> wrote:
> Hi
>
> If I try to capture the last record, what is missing?
>
> CREATE PROCEDURE SP_PRODUCT_PRECE (
> P_ESTATION INTEGER,
> P_PRODUCT CHAR (4))
> RETURNS (
> P_PRICE FLOAT)
> AS
> BEGIN
> SELECT PRECIO_COMPRA
> FROM PRODUCTS_PRICES
> WHERE ID_ESTACION = :P_ESTACION AND
> ID_PRODUCT = :P_PRODUCT
> ORDER BY DATE_OF_CHANGE,
> TIME_OF_CHANGE
> INTO :P_PRICE
> END
>
> This Select returns multiple records, But I want just the last.
>
> Regards
>
> Fernando Buitrago
>
first change the order by clause to
ORDER BY DATE_OF_CHANGE DESC,
TIME_OF_CHANGE DESC

so the last record become the first and exit
INTO :P_PRICE;
EXIT;
END