UFN_RELATIONSHIP_ISCURRENTCONTACT
Determines if a relationship is currently a valid contact for a constituent based on ISCONTACT, STARTDATE, and ENDDATE fields.
Return
Return Type |
---|
bit |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@RELATIONSHIPID | uniqueidentifier | IN | |
@CONSTITUENTID | uniqueidentifier | IN |
Definition
Copy
create function dbo.UFN_RELATIONSHIP_ISCURRENTCONTACT
(
@RELATIONSHIPID uniqueidentifier,
@CONSTITUENTID uniqueidentifier
)
returns bit
as begin
declare @CURRENTDATE datetime;
declare @UPPERBOUND datetime;
declare @LOWERBOUND datetime;
set @CURRENTDATE = getdate();
set @UPPERBOUND = dbo.UFN_DATE_GETLATESTTIME(@CURRENTDATE);
set @LOWERBOUND = dbo.UFN_DATE_GETEARLIESTTIME(@CURRENTDATE);
if exists(
select
1
from
dbo.RELATIONSHIP
where
ID = @RELATIONSHIPID
and RELATIONSHIPCONSTITUENTID = @CONSTITUENTID
and ISCONTACT = 1
and (STARTDATE is null or STARTDATE <= @UPPERBOUND)
and (ENDDATE is null or ENDDATE >= @LOWERBOUND)
)
return 1;
return 0;
end