Not getting SUM value returned from stored procedure
Posted on 2007-11-25
Table Transaction has Transaction_Type declared as char(6) and it can have the value Debit or Credit.
It has Transaction_Amount declared as money.
Stored Procedure (below) is always returning a value of 0.0.
I've tried it both with 'Debit' and 'Debit '. Same result.
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE PROCEDURE [dbo].SP_GetBalance
DECLARE @Debits money
DECLARE @Credits money
SET @Debits = 0
SET @Credits = 0
SET NOCOUNT ON;
SELECT @Debits = SUM ([Transaction].[Transaction_Amount])
WHERE [Transaction].[Transaction_Type] = 'Debit '
SELECT @Credits = SUM([Transaction].[Transaction_Amount])
WHERE [Transaction].[Transaction_Type] = 'Credit'
SET @Balance = @Credits - @Debits