UFN_EVENT_VALIDAPPEAL_NOTINUSEBYOTHEREVENT

Validates that the appeal is not linked to more than one event.

Return

Return Type
bit

Parameters

Parameter Parameter Type Mode Description
@EVENTID uniqueidentifier IN
@APPEALID uniqueidentifier IN

Definition

Copy


CREATE function dbo.UFN_EVENT_VALIDAPPEAL_NOTINUSEBYOTHEREVENT
(
    @EVENTID uniqueidentifier = null,
    @APPEALID uniqueidentifier = null
)
returns bit with execute as caller
as
begin
    -- An appeal can only be linked to one event.

    if exists
    (
        select
            ID
        from
            dbo.EVENT
        where
            (EVENT.APPEALID = @APPEALID)
            and (EVENT.ID <> @EVENTID)
    )    -- Another event has this appeal as its Team fundraising appeal.

        return 0;

    if exists
    (
        select
            ID
        from
            dbo.EVENTAPPEAL
        where
            (EVENTAPPEAL.APPEALID = @APPEALID)
            and (EVENTAPPEAL.EVENTID <> @EVENTID)
    )    -- Another event has this appeal linked in the 'Appeals' section.

        return 0;

    if exists
    (
        select
            1
        from
            dbo.EVENT
            inner join dbo.EVENTAPPEAL on 
                (EVENTAPPEAL.EVENTID = EVENT.ID)
                and (EVENTAPPEAL.APPEALID = EVENT.APPEALID)
        where
            (EVENTAPPEAL.EVENTID = @EVENTID)
            and (EVENTAPPEAL.APPEALID = @APPEALID)
    )    -- This event has the appeal as its Team fundraising appeal and another link to it from the 'Appeals' section.

        return 0;

    return 1;
end