CREATE FUNCTION [dbo].[fn_GetSMSCreditAllocatedBalance] (@customerCode VARCHAR(50))
RETURNS INT
AS 
BEGIN
   RETURN
	(SELECT	SUM(ISNULL(S.qty,0))
	FROM	pal_SMSCreditLog S
			JOIN pal_SMSCreditTransactionType T
				ON T.recId = S.transactionType
	WHERE	S.customerCode = @customerCode
			AND T.transactionType = 'Allocated')
END
