UFN_PROSPECTMANAGERHISTORY_VALIDCONSTITUENT
Validates the start and end dates of a manager on a prospect. Assumes end start is always on or after the start date.
Return
Return Type |
---|
bit |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@PROSPECTMANAGERHISTORYID | uniqueidentifier | IN | |
@PROSPECTID | uniqueidentifier | IN | |
@DATEFROM | datetime | IN | |
@DATETO | datetime | IN |
Definition
Copy
CREATE function dbo.UFN_PROSPECTMANAGERHISTORY_VALIDCONSTITUENT
(
@PROSPECTMANAGERHISTORYID uniqueidentifier,
@PROSPECTID uniqueidentifier,
@DATEFROM datetime,
@DATETO datetime
)
returns bit
with execute as caller
as begin
if exists (
select top 1
ID
from
dbo.PROSPECTMANAGERHISTORY
where
ID <> @PROSPECTMANAGERHISTORYID and
PROSPECTID = @PROSPECTID and
(
(@DATEFROM < convert(date, datefrom) and @DATETO > convert(date, datefrom)) or
(@DATEFROM = convert(date, datefrom) and @DATETO > @DATEFROM and convert(date, dateto) > convert(date, datefrom)) or
(@DATEFROM > convert(date, datefrom) and @DATEFROM < convert(date, dateto)) or
(convert(date, datefrom) is null and (@DATEFROM is null or @DATEFROM < convert(date, dateto))) or
(@DATEFROM is null and (convert(date, datefrom) is null or convert(date, datefrom) < @DATETO))
)
)
return 0;
return 1;
end