USP_DATALIST_FAFTEAMMONEY_UNITPERFORMANCE

Data list for FAF team money unit performance.

Parameters

Parameter Parameter Type Mode Description
@EVENTID uniqueidentifier IN Input parameter indicating the context ID for the data list.

Definition

Copy


CREATE procedure dbo.USP_DATALIST_FAFTEAMMONEY_UNITPERFORMANCE(@EVENTID uniqueidentifier)
as
    set nocount on;

    declare @TEMP_TEAMTOTAL as table
    (        
        ID uniqueidentifier,
        TOTAL money
    );

  insert into @TEMP_TEAMTOTAL
    (        
        ID, TOTAL
    )
  select 
    TE.TEAMFUNDRAISINGTEAMID, 
    dbo.UFN_REVENUE_GETTEAMRAISEDTOTAL(TE.TEAMFUNDRAISINGTEAMID, TE.EVENTID) as TOTAL
  from TEAMEXTENSION TE(nolock)
  where TE.TYPECODE = 1
  and TE.EVENTID = @EVENTID;

    declare  @TEMP_TEAMGROUPTOTAL as table
    (        
        NAME nvarchar(100),
        GROUPTOTAL money,
        ORDERNUMBER int
    );

    -- total<500

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, GROUPTOTAL, ORDERNUMBER
    )
    select 
        '$1-$500'
        , ISNULL(SUM(TOTAL), 0)
        , '1'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL < 500;

    -- 500<total<=2500

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, GROUPTOTAL, ORDERNUMBER
    )
    select 
        '$501-$2500'
        , ISNULL(SUM(TOTAL), 0)
        , '2'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 500 AND TT.TOTAL <= 2500;

    -- 2500<total<=5000

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, GROUPTOTAL, ORDERNUMBER
    )
    select 
        '$2501-$5000'
        , ISNULL(SUM(TOTAL), 0)
        , '3'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 2501 AND TT.TOTAL <= 5000;

    -- 5000<total<=10000

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, GROUPTOTAL, ORDERNUMBER
    )
    select 
        '$5001-$10000'
        , ISNULL(SUM(TOTAL), 0)
        , '4'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 5000 AND TT.TOTAL <= 10000;

    -- 10000<total<=25000

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, GROUPTOTAL, ORDERNUMBER
    )
    select 
        '$10001-$25000'
        , ISNULL(SUM(TOTAL), 0)
        , '5'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 10000 AND TT.TOTAL <= 25000;

    -- 25000<total<=50000

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, GROUPTOTAL, ORDERNUMBER
    )
    select 
        '$25001-$50000'
        , ISNULL(SUM(TOTAL), 0)
        , '6'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 25000 AND TT.TOTAL <= 50000;

    -- total>50000

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, GROUPTOTAL, ORDERNUMBER
    )
    select 
        '$50001+'
        , ISNULL(SUM(TOTAL), 0)
        , '7'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 50000;

    select NAME
        ,GROUPTOTAL
    from @TEMP_TEAMGROUPTOTAL
    order by ORDERNUMBER