Skip to content

Instantly share code, notes, and snippets.

@kwestground
Last active September 25, 2020 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwestground/49ba9be0c02e0d15fb3b2c67431198aa to your computer and use it in GitHub Desktop.
Save kwestground/49ba9be0c02e0d15fb3b2c67431198aa to your computer and use it in GitHub Desktop.
Scalar function to get lastest currency rate from SAP Business One HANA
ALTER FUNCTION POLR_LATEST_CURRENCY_RATE(CurrencyCode char(3))
RETURNS result decimal(15,2)
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER AS
BEGIN
DECLARE found INT := 0;
SELECT COUNT(1) INTO found FROM "ORTT" WHERE "Currency" = :CurrencyCode AND "RateDate" <= CURRENT_DATE;
IF :found > 0
THEN
SELECT "Rate" INTO result FROM "ORTT" WHERE "Currency" = :CurrencyCode AND "RateDate" <= CURRENT_DATE ORDER BY "RateDate" DESC LIMIT 1;
ELSE
SELECT 1 INTO result FROM "DUMMY";
END IF;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment