UFN_CONSTITUENT_ISPROSPECT

This functions returns whether a constituent is a prospect as of the given date.

Return

Return Type
bit

Parameters

Parameter Parameter Type Mode Description
@CONSTITUENTID uniqueidentifier IN

Definition

Copy


        create function dbo.UFN_CONSTITUENT_ISPROSPECT(@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.PROSPECTDATERANGE
                where
                    PROSPECTDATERANGE.CONSTITUENTID = @CONSTITUENTID and
                    (PROSPECTDATERANGE.DATEFROM <= @UPPERBOUND or PROSPECTDATERANGE.DATEFROM is null) and
                    (PROSPECTDATERANGE.DATETO >= @LOWERBOUND or PROSPECTDATERANGE.DATETO is null)
            ) return 1;

            return 0;
        end