SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FNA_GET_REWARD_POINTS]()
RETURNS @list TABLE (totalPoints INT, RegPoint INT, TranPoint INT)
AS  
BEGIN
    INSERT INTO @list (totalPoints, RegPoint, TranPoint)
    SELECT 
        SUM(CASE WHEN PromotionType IN ('REGISTRATION', 'TRANSACTION') THEN Points ELSE 0 END) AS totalPoints,
        SUM(CASE WHEN PromotionType = 'REGISTRATION' THEN Points ELSE 0 END) AS RegPoint,
        SUM(CASE WHEN PromotionType = 'TRANSACTION' THEN Points ELSE 0 END) AS TranPoint
    FROM TBL_PROMOTION_SETUP;

    RETURN;
END
