God day!I just want to ask on how can I call the function Ive made to get the balance of a certain account..Here is the function Ive created:USE [Pizza_Financial]GO/****** Object: UserDefinedFunction [dbo].[get_accntbalance] Script Date: 07/04/2012 11:24:23 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER FUNCTION [dbo].[get_accntbalance](@accntid as bigint)RETURNS MoneyWITH EXECUTE AS CALLERASBEGIN declare @debitbalance as money declare @creditbalance as money declare @remainingbalance as money set @debitbalance=(select sum(debit_amt) from tbl_account_transactions_detail where debit_accnt_ID=@accntid) set @creditbalance=(select sum(credit_amt) from tbl_account_transactions_detail where credit_accnt_ID=@accntid) set @remainingbalance=@debitbalance-@creditbalance RETURN(@remainingbalance);END;
Here is my stored procedures to get all accounts, I am thinking to create a variable in the select statement like currentbalance and call the function but I cant make it running.USE [Pizza_Financial]GO/****** Object: StoredProcedure [dbo].[Show_All_Accnts_byType] Script Date: 07/04/2012 11:23:43 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- ============================================-- Author: <Author,,Name>-- Create date: <Create Date,,>-- Description: <Description,,>-- =============================================ALTER PROCEDURE [dbo].[Show_All_Accnts_byType]@accntcategoryID as int,@accntypeid as bigint,@isaccnt_current as bitAS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; if(@accntypeid<>'') and (@accntcategoryID<>'') begin SELECT * FROM tbl_accountlist al INNER JOIN tbl_accnt_type at ON at.accnttypename=(select at.accnttypename where at.accnttypeid=al.AccountType) WHERE (al.Accntstatus=1 and al.AccountCategoryID=@accntcategoryID and al.AccountType= @accntypeid and al.IsCurrent=@isaccnt_current and al.IsSubAccnt=0)ORDER BY AccntNo ASC endEND
Thank you for helping!