Validating the result of a Case
I'm getting the interval between two dates in days, I want to validate if the result is greater than 120 days, is it a better way I'm doing?
DECLARE @DataInicioVigencia datetime; -- ='2018-11-30T00:00:00';
DECLARE @DataInicioVigenciaProgramada datetime = '2018-11-30T00:00:00';
DECLARE @DataAdmissao datetime = '2018-07-01T00:00:00';
select
CASE
WHEN isdate(@DataInicioVigencia) = 1 AND
( ABS(DATEDIFF(day,@DataInicioVigencia,@DataAdmissao)) > 120 ) then 1
WHEN isdate(@DataInicioVigenciaProgramada) = 1 AND
( ABS(DATEDIFF(day,@DataInicioVigenciaProgramada,@DataAdmissao)) > 125 ) then 2
ELSE 3
END as 'PRAZO'
from FUNCIONARIOS
--mostrar o cálculo
select ABS(DATEDIFF(day,@DataInicioVigencia,@DataAdmissao))
select ABS(DATEDIFF(day,@DataInicioVigenciaProgramada,@DataAdmissao))