UFN_FUNDRAISER_GETDEFAULTSITENAME

Fetches the name of the default site (if any) for a fundraiser

Return

Return Type
nvarchar(1024)

Parameters

Parameter Parameter Type Mode Description
@CONSTITUENTID uniqueidentifier IN

Definition

Copy


CREATE function dbo.UFN_FUNDRAISER_GETDEFAULTSITENAME(@CONSTITUENTID uniqueidentifier)
returns nvarchar(1024)
with execute as caller
as begin
    declare @siteId uniqueidentifier
  declare @currentDate date = dbo.UFN_DATE_GETEARLIESTTIME(getdate())

    select @siteId = SITEID 
    from dbo.ORGANIZATIONPOSITIONHOLDER holder
    join dbo.ORGANIZATIONPOSITION pos on holder.POSITIONID = pos.ID
    where CONSTITUENTID = @CONSTITUENTID
  and DATEFROM <= @currentDate
  and (DATETO is null OR DATETO >= @currentDate)

    -- return the name of the site, if any; else return empty string

    declare @name nvarchar(1024)
    if (@siteId is null)
        set @name = '';
    else
        select @name = NAME from dbo.[SITE] where ID = @siteId;
    return @name    
end