I'm tasked with analyzing a T-SQL function that repeatedly nests an IIF function inside a MAX function. Am I missing something or does this simply not change the output at all?
DECLARE @firstVal INT = 1;
SELECT [NotWrappedIff] = IIF(1=2, @firstVal, NULL)
SELECT [MaxWrappedIff] = MAX(IIF(1=2, @firstVal, NULL))
The actual code has a additional isnull, and dateadd functions nested, but the structure is the same. The false value of the nested IIFs are all NULL. Actual code:
SomeIdToKeep = max(iif(isnull(SomeStartTime, SomeOtherStartTime) < @parmStartTime and dateadd(hour, HourIntVal, isnull(SomeStartTime, SomeOtherStartTime)) >= @parmStartTime, SomeId, null))