Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8119271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:45:20+00:00 2026-06-06T04:45:20+00:00

I have make a procedure where two queries return values for a and b

  • 0

I have make a procedure where two queries return values for

a and b

Substract of a and b is c

c = a-b;

if value of c is positive then procedure return correct value and if value of c is in negative then procedure return NULL.

This is my procedure.

DELIMITER $$

USE `db`$$

DROP PROCEDURE IF EXISTS `getOutStandingBalance`$$

CREATE DEFINER=`root`@`%` PROCEDURE `getOutStandingBalance`(OUT Total DOUBLE SIGNED,IN OID INT)
    DETERMINISTIC
    COMMENT 'A procedure'
BEGIN
    DECLARE Credit DOUBLE;
    DECLARE Debit  DOUBLE;
    SELECT SUM(transaction.Amount) INTO Credit FROM `transaction` WHERE transaction.IsDeleted=0 AND transaction.IsCredit=1 AND transaction.OID=OID;

    SELECT SUM(transaction.Amount) INTO Debit FROM `transaction` WHERE transaction.IsDeleted=0 AND transaction.IsCredit=0 AND transaction.OID=OID;

    SET Total = (Credit-Debit);
END$$

DELIMITER ;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:45:22+00:00Added an answer on June 6, 2026 at 4:45 am

    If no rows are found for either of the credit or debit for the transaction, the variables will be NULL. In SQL, any calculation with a NULL results in a NULL.

    To fix, do this:

    SET Total = ifnull(Credit, 0) - ifnull(Debit, 0);
    

    Also, change the signature to

    OUT Total decimal(16,2)
    

    or similar. Why are you using DOUBLE SIGNED?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that needs to return something from one of two
I'm trying to write a stored procedure that will return two calculated values for
I have make this script: $(#comments .comment .links).hide(); $(#comments .comment).hover( function() { $(.links, this).stop(true).slideDown(300);
Using this sample : I have make my own Fragment that holds tabhost and
I have to make a graph based on a list of items. For this
I have to make the same program for two different companies (different logo, different
I have two sources of clinical procedure billing information that I have added together
I have a stored procedure on SQL Server 2008 that copies certain values from
I have two TSQL EXEC statements EXECUTE (N'MyDynamicallyGeneratedStoredProcedure') -- return 0 on success SELECT
I have a cursor which returns two values: one which I will use (and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.