Skip to content

Instantly share code, notes, and snippets.

@Jacob-Anderson-Developer
Last active April 27, 2025 16:25
Show Gist options
  • Save Jacob-Anderson-Developer/ee6aac9821bbb0fd655292bf1dd2c373 to your computer and use it in GitHub Desktop.
Save Jacob-Anderson-Developer/ee6aac9821bbb0fd655292bf1dd2c373 to your computer and use it in GitHub Desktop.
This is the SQL you will run to create the get balance procedure.
CREATE OR REPLACE PROCEDURE YourLibrary.GETBALANCE (
OUT BALANCE DECIMAL(15, 2)
)
NOT DETERMINISTIC
BEGIN
SET BALANCE =
COALESCE((SELECT SUM(AMOUNT) FROM YourLibrary.BALANCETAB WHERE TRANSTYPE = 'D'), 0)
-
COALESCE((SELECT SUM(AMOUNT) FROM YourLibrary.BALANCETAB WHERE TRANSTYPE = 'W'), 0);
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment