
ALTER FUNCTION [dbo].[FNA_GET_AVAILABLE_BALANCE_POINTS](@CustomerId BIGINT)
RETURNS MONEY
AS  
BEGIN
	DECLARE @BALANCE MONEY

	SELECT @BALANCE = ISNULL(SUM(CASE WHEN tranType = 'CR' THEN amount ELSE -1 * amount END), 0)
	FROM Customer_Promotion CP(NOLOCK)
	WHERE sourceCustomerId = @CustomerId

	RETURN ISNULL(@BALANCE, 0)
END