That's the strange part, we never made any changes to those functions and SP for years and all of a sudden it's doing this. Here's the fn_calculatecasehealth :
CREATE FUNCTION fn_calculatecasehealth
(@tempcasenumberid int)
RETURNS int
WITH ENCRYPTION
AS
BEGIN
DECLARE @operationresult_casehealth int
DECLARE @local_caseisactive int, @local_currentprocessowner int
DECLARE @local_receivedrequestforinvestigation datetime, @local_discoverydate datetime, @local_misconductdate datetime
DECLARE @local_regionalofficecaseassignment datetime
DECLARE @local_statuteoflimitationdate datetime
DECLARE @tempcasedatestable table(casedatesid int, casenumberid int, caseisactive bit,
currentprocessowner int, prioritylevelid int, casehealth int, iscentralintakecomplete bit,
isinvestigationcomplete bit, isdisciplinecomplete bit, receivedrequestforinvestigation datetime,
centralintakecasecalendar datetime, centralintakecaseagentassignment datetime, centralintakepaneldecision datetime,
centralintakecomplete datetime, regionalofficecaseassignment datetime, investigatorcaseassignment datetime,
investigationcomplete datetime, disciplinecomplete datetime, reportedmisconductdate datetime,
reporteddiscoverydate datetime, misconductdate datetime, discoverydate datetime, originallysigneddate datetime,
requesteddate datetime, isemploymentadvocacyprosecutionteamcomplete bit, employmentadvocacyprosecutionteamcomplete datetime,
verticaladvocatecaseassignment datetime, assesscriticalcasedatescomplete datetime, casecloseddate datetime);
-- Set default case health
SET @operationresult_casehealth = 0
-- Acquire case dates information
INSERT INTO @tempcasedatestable(casedatesid, casenumberid, caseisactive, currentprocessowner,
prioritylevelid, casehealth, iscentralintakecomplete, isinvestigationcomplete, isdisciplinecomplete, receivedrequestforinvestigation,
centralintakecasecalendar, centralintakecaseagentassignment, centralintakepaneldecision,
centralintakecomplete, regionalofficecaseassignment, investigatorcaseassignment,
investigationcomplete, disciplinecomplete, reportedmisconductdate,
reporteddiscoverydate, misconductdate, discoverydate, originallysigneddate,
requesteddate, isemploymentadvocacyprosecutionteamcomplete, employmentadvocacyprosecutionteamcomplete,
verticaladvocatecaseassignment, assesscriticalcasedatescomplete, casecloseddate)
SELECT casedatesid, casenumberid, caseisactive, currentprocessowner,
prioritylevelid, casehealth, iscentralintakecomplete, isinvestigationcomplete, isdisciplinecomplete, receivedrequestforinvestigation,
centralintakecasecalendar, centralintakecaseagentassignment, centralintakepaneldecision,
centralintakecomplete, regionalofficecaseassignment, investigatorcaseassignment,
investigationcomplete, disciplinecomplete, reportedmisconductdate,
reporteddiscoverydate, misconductdate, discoverydate, originallysigneddate,
requesteddate, isemploymentadvocacyprosecutionteamcomplete, employmentadvocacyprosecutionteamcomplete,
verticaladvocatecaseassignment, assesscriticalcasedatescomplete, casecloseddate
FROM casedates
WHERE casenumberid = @tempcasenumberid
-- Acquire statute of limitation date
SET @local_statuteoflimitationdate = dbo.fn_calculatestatuteoflimitationdate(@tempcasenumberid)
-- Case is active
SELECT @local_caseisactive = (SELECT caseisactive FROM casedates WHERE casenumberid = @tempcasenumberid)
-- Current Process Owner
SELECT @local_currentprocessowner = (SELECT currentprocessowner FROM casedates WHERE casenumberid = @tempcasenumberid)
-- Received for Request for Investigation
SELECT @local_receivedrequestforinvestigation = (SELECT receivedrequestforinvestigation FROM casedates WHERE casenumberid = @tempcasenumberid)
-- Discovery Date
SELECT @local_discoverydate = (SELECT discoverydate FROM casedates WHERE casenumberid = @tempcasenumberid)
-- Misconduct Date
SELECT @local_misconductdate = (SELECT misconductdate FROM casedates WHERE casenumberid = @tempcasenumberid)
-- Regional Office Assignment
SELECT @local_regionalofficecaseassignment = (SELECT regionalofficecaseassignment FROM casedates WHERE casenumberid = @tempcasenumberid)
IF ((1=@local_currentprocessowner) AND (DATEDIFF(dd, @local_receivedrequestforinvestigation, GETDATE()) >= 14)) --CentralIntake=1 (14/30 Day warning)
BEGIN
SET @operationresult_casehealth = 2 --Warning=2
END
ELSE IF ((1=@local_currentprocessowner) AND (DATEDIFF(dd, @local_receivedrequestforinvestigation, GETDATE()) > 0) AND
(DATEDIFF(dd, @local_receivedrequestforinvestigation, GETDATE()) < 14))
BEGIN
SET @operationresult_casehealth = 1 --Normal=1
END
ELSE IF ((1=@local_currentprocessowner) AND (DATEDIFF(dd, @local_receivedrequestforinvestigation, GETDATE()) < 0))
BEGIN
SET @operationresult_casehealth = 0 --Unknown=0
END
ELSE IF ((2=@local_currentprocessowner) AND (DATEDIFF(dd, @local_regionalofficecaseassignment, GETDATE()) >= 120)) --(60 investigative days left)
BEGIN
SET @operationresult_casehealth = 2 --Warning=2
END
ELSE IF ((2=@local_currentprocessowner) AND (DATEDIFF(dd, @local_regionalofficecaseassignment, GETDATE()) > 0) AND --(More than 180 Days before SOL)
(DATEDIFF(dd, @local_regionalofficecaseassignment, GETDATE()) < 120))
BEGIN
SET @operationresult_casehealth = 1 --Normal=1
END
ELSE IF ((2=@local_currentprocessowner) AND (DATEDIFF(dd, @local_regionalofficecaseassignment, GETDATE()) < 0))
BEGIN
SET @operationresult_casehealth = 0 --Unknown=0
END
ELSE IF ((3=@local_currentprocessowner) AND
((@local_discoverydate < CONVERT(datetime, '1/1/1950')) OR (@local_misconductdate < CONVERT(datetime, '1/1/1950'))))
BEGIN
SET @operationresult_casehealth = 0 --Unknown=0
END
ELSE IF ((3=@local_currentprocessowner) AND (DATEDIFF(dd, GETDATE(), @local_statuteoflimitationdate) <= 60)) --Discipline (60 days before SOL)
BEGIN
SET @operationresult_casehealth = 2 --Warning=2
END
ELSE IF ((3=@local_currentprocessowner) AND (DATEDIFF(dd, GETDATE(), @local_statuteoflimitationdate) > 60)) --(More than 60 days before SOL)
BEGIN
SET @operationresult_casehealth = 1 --Normal=1
END
-- Statute date has been blown
IF ((DATEDIFF(dd, GETDATE(), @local_statuteoflimitationdate) < 0) AND
(@local_discoverydate > CONVERT(datetime, '1/1/1950')) AND (@local_misconductdate > CONVERT(datetime, '1/1/1950')))
BEGIN
SET @operationresult_casehealth = 3 --Critical=3
END
-- Set case health to Normal if the case is closed (last conditional)
IF (0 = @local_caseisactive)
BEGIN
SET @operationresult_casehealth = 1 --Normal=1
END
RETURN @operationresult_casehealth
END
GO