UFN_BANKACCOUNT_GETCURRENTBALANCE

This function returns the balance of a bank account.

Return

Return Type
decimal(19, 4)

Parameters

Parameter Parameter Type Mode Description
@BANKACCOUNTID uniqueidentifier IN

Definition

Copy


            CREATE function dbo.UFN_BANKACCOUNT_GETCURRENTBALANCE
                (
                    @BANKACCOUNTID uniqueidentifier
                )
                returns decimal(19, 4)
                with execute as caller
                as begin
                    declare @BALANCE decimal(19, 4);

                    select
                        @BALANCE = coalesce(SUM(case when STATUSCODE = 4 then 0 else case when GENERALLEDGERTRANSACTION = 2 then -TRANSACTIONAMOUNT else TRANSACTIONAMOUNT end end ), 0)
                    from
                        dbo.BANKACCOUNTTRANSACTION
                    where
                        BANKACCOUNTTRANSACTION.BANKACCOUNTID = @BANKACCOUNTID and
                        BANKACCOUNTTRANSACTION.TRANSACTIONDATE <= getdate()
            and BANKACCOUNTTRANSACTION.PROCESSING = 0
            and BANKACCOUNTTRANSACTION.DELETED = 0
            --and BANKACCOUNTTRANSACTION.STATUSCODE <> 4


                    return @BALANCE
                end