USP_DATALIST_FAFTEAMCOUNT_UNITPERFORMANCE

Data list for FAF team count 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_FAFTEAMCOUNT_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),
        NUMBERCOUNT int,
        ORDERNUMBER int
    );

    -- total=0

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, NUMBERCOUNT, ORDERNUMBER
    )
    select 
        '$0'
        , COUNT(*)
        , '1'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL = 0;

    -- total<=500

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, NUMBERCOUNT, ORDERNUMBER
    )
    select 
        '$1-$500'
        , COUNT(*)
        , '2'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 0 AND TT.TOTAL <= 500;

    -- 500<total<=2500

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, NUMBERCOUNT, ORDERNUMBER
    )
    select 
        '$501-$2500'
        , COUNT(*)
        , '3'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 500 AND TT.TOTAL <= 2500;

    -- 2500<total<=5000

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, NUMBERCOUNT, ORDERNUMBER
    )
    select 
        '$2501-$5000'
        , COUNT(*)
        , '4'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 2500 AND TT.TOTAL <= 5000;

    -- 5000<total<=10000

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, NUMBERCOUNT, ORDERNUMBER
    )
    select 
        '$5001-$10000'
        , COUNT(*)
        , '5'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 5000 AND TT.TOTAL <= 10000;

    -- 10000<total<=25000

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, NUMBERCOUNT, ORDERNUMBER
    )
    select 
        '$10001-$25000'
        , COUNT(*)
        , '6'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 10000 AND TT.TOTAL <= 25000;

    -- 25000<total<=50000

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, NUMBERCOUNT, ORDERNUMBER
    )
    select 
        '$25001-$50000'
        , COUNT(*)
        , '7'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 25000 AND TT.TOTAL <= 25000;

    -- total>50000

    insert into @TEMP_TEAMGROUPTOTAL
    (        
        NAME, NUMBERCOUNT, ORDERNUMBER
    )
    select 
        '$50001+'
        , COUNT(*)
        , '8'
    from @TEMP_TEAMTOTAL TT 
    where TT.TOTAL > 50000;

    select NAME
        ,NUMBERCOUNT
    from @TEMP_TEAMGROUPTOTAL
    order by ORDERNUMBER