You cannot have a comparison expression in CASE like
I would consider this option, which changes the comparison with a normal expression
...
AND
CASE @ActiveInactive
WHEN 'Active' THEN DATEDIFF(day, o.[orderinactivedate], o.[orderactivedate])
WHEN 'Inactive' THEN DATEDIFF(day, o.[orderactivedate], o.[orderinactivedate])
END > 0
Or this, and you can have a computed column in the expression SIGN()
SIGN(DATEDIFF(day, o.[orderinactivedate], o.[orderactivedate])) =
CASE WHEN @ActiveInactive WHEN 'Active' THEN 1 WHEN 'InActive' THEN -1 END
source
share