Last active
September 25, 2020 13:29
-
-
Save kwestground/49ba9be0c02e0d15fb3b2c67431198aa to your computer and use it in GitHub Desktop.
Scalar function to get lastest currency rate from SAP Business One HANA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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