UFN_DESIGNATIONLEVELRELATEDSTAFF_ISUNIQUE
Returns a bit indicating if a related staff already exists for a fundraising purpose for specific dates.
Return
Return Type |
---|
bit |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@CONSTITUENTID | uniqueidentifier | IN | |
@ROLECODEID | uniqueidentifier | IN | |
@DESIGNATIONLEVELID | uniqueidentifier | IN | |
@STARTDATE | date | IN | |
@ENDDATE | date | IN |
Definition
Copy
create function dbo.UFN_DESIGNATIONLEVELRELATEDSTAFF_ISUNIQUE(
@CONSTITUENTID uniqueidentifier,
@ROLECODEID uniqueidentifier,
@DESIGNATIONLEVELID uniqueidentifier,
@STARTDATE date,
@ENDDATE date
)
returns bit
with execute as caller
as begin
declare @DUPLICATECOUNT int;
select
@DUPLICATECOUNT = count(*)
from
dbo.DESIGNATIONLEVELRELATEDSTAFF
where
(CONSTITUENTID = @CONSTITUENTID) and
(ROLECODEID = @ROLECODEID) and
(DESIGNATIONLEVELID = @DESIGNATIONLEVELID) and
(
( ENDDATE between @STARTDATE and @ENDDATE) or
(@ENDDATE between STARTDATE and ENDDATE) or
( STARTDATE between @STARTDATE and @ENDDATE) or
(@STARTDATE between STARTDATE and ENDDATE) or
( STARTDATE is null and @STARTDATE <= ENDDATE) or
(@STARTDATE is null and STARTDATE <= @ENDDATE) or
( ENDDATE is null and @ENDDATE >= STARTDATE) or
(@ENDDATE is null and ENDDATE >= @STARTDATE) or
(@STARTDATE is null and STARTDATE is null) or
(@ENDDATE is null and ENDDATE is null) or
(@STARTDATE is null and @ENDDATE is null) or
( STARTDATE is null and ENDDATE is null)
);
if (@DUPLICATECOUNT <= 1)
return 1;
return 0;
end