Subject RE: [ib-support] The Last Record.......in Selects
Author Thomas Steinmaurer
Fernando,

> 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.

you could achieve this with Firebird by using an descending
ORDER BY clause and the FIRST keyword.

For example:

CREATE PROCEDURE SP_PRODUCT_PRECE (
P_ESTATION INTEGER,
P_PRODUCT CHAR (4))
RETURNS (
P_PRICE FLOAT)
AS
BEGIN
SELECT FIRST 1 PRECIO_COMPRA
FROM PRODUCTS_PRICES
WHERE ID_ESTACION = :P_ESTACION AND
ID_PRODUCT = :P_PRODUCT
ORDER BY DATE_OF_CHANGE DESC,
TIME_OF_CHANGE DESC
INTO :P_PRICE;
SUSPEND;
END


Regards,
Thomas Steinmaurer
http://www.iblogmanager.com

See you in 3 DAYS at the First European Firebird Conference
in Fulda, Germany
http://www.firebird-conference.com