fnFundRaiserTeamsCreatedAtLevel
Return
Return Type |
---|
int |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@RootFundraiserID | int | IN | |
@Level | int | IN |
Definition
Copy
create function [dbo].[fnFundRaiserTeamsCreatedAtLevel](
@RootFundraiserID int,
@Level int
)
returns int
as
begin
--Limiting to 5 Team Levels for now.
declare @retTeamIDs table (TeamID int primary key not null)
declare @recordcount int
if (@Level = 1)
begin
insert into @retTeamIDs
select id from FundraiserTeams
where ReportsToID is null and RootFundraiserID = @RootFundraiserID
end
if (@Level = 2)
begin
insert into @retTeamIDs
select id from FundraiserTeams
where ReportsToID in
(select id from FundraiserTeams
where ReportsToID is null and RootFundraiserID = @RootFundraiserID)
end
if (@Level = 3)
begin
insert into @retTeamIDs
select id from FundraiserTeams
where ReportsToID in
(select id from FundraiserTeams
where ReportsToID in
(select id from FundraiserTeams
where ReportsToID is null and RootFundraiserID = @RootFundraiserID))
end
if (@Level = 4)
begin
insert into @retTeamIDs
select id from FundraiserTeams
where ReportsToID in
(select id from FundraiserTeams
where ReportsToID in
(select id from FundraiserTeams
where ReportsToID in
(select id from FundraiserTeams
where ReportsToID is null and RootFundraiserID = @RootFundraiserID)))
end
if (@Level = 5)
begin
insert into @retTeamIDs
select id from FundraiserTeams
where ReportsToID in
(select id from FundraiserTeams
where ReportsToID in
(select id from FundraiserTeams
where ReportsToID in
(select id from FundraiserTeams
where ReportsToID in
(select id from FundraiserTeams
where ReportsToID is null and RootFundraiserID = @RootFundraiserID))))
end
select @recordcount = count(*) from @retTeamIDs
return @recordcount
end