UFN_CONSTITUENT_ISFORMERVOLUNTEER

This functions returns whether a constituent had a volunteer constituency in the past.

Return

Return Type
bit

Parameters

Parameter Parameter Type Mode Description
@CONSTITUENTID uniqueidentifier IN

Definition

Copy


        create function dbo.UFN_CONSTITUENT_ISFORMERVOLUNTEER(@CONSTITUENTID uniqueidentifier)
        returns bit
        with execute as caller
        as begin
            declare @CURRENTDATE datetime;
            set @CURRENTDATE = getdate();

            declare @UPPERBOUND datetime;
            set @UPPERBOUND = dbo.UFN_DATE_GETLATESTTIME(@CURRENTDATE);

            declare @LOWERBOUND datetime;
            set @LOWERBOUND = dbo.UFN_DATE_GETEARLIESTTIME(@CURRENTDATE);

            if exists(
                select
                    ID
                from
                    dbo.VOLUNTEERDATERANGE
                where
                    VOLUNTEERDATERANGE.CONSTITUENTID = @CONSTITUENTID and
                    (VOLUNTEERDATERANGE.DATETO < @LOWERBOUND)
            ) return 1;

            return 0;
        end