This code works fine:
select fk, max(case when 1 = 0 then 1 else null end) maxx from (values(1, null), (1, null)) x(fk, a) group by fk;
exit:
fk maxx ----------- ----------- 1 NULL
from:
Warning: Null value is eliminated by an aggregate or other SET operation.
But this code:
select fk, max(a) maxx from (values(1, null), (1, null)) x(fk, a) group by fk;
enter the error:
Msg 8117, Level 16, State 1, Line 5 Operand data type NULL is invalid for max operator.
In both cases, sql server compute max from null and null ? Is not it?
sql sql-server tsql
Ruslan K.
source share