As SQL Server does not support ignore nulls in first_value function, how can we get the first non null value in a window without defining a new column?
I tried to use COALESCE(), however it didn't work as a window function.
As SQL Server does not support ignore nulls in first_value function, how can we get the first non null value in a window without defining a new column?
I tried to use COALESCE(), however it didn't work as a window function.
As has been mentioned,
FIRST_VALUEdoes supportIGNORE NULLS(in SQL Server 2022+). As such you can do:Emulating this for
FIRST_VALUEisn't too difficult without the syntax though, just add aCASEto yourORDER BYon your column to order theNULLvalues later:This'll force values that are
NULLto be ordered later and so can only be the first value if all the values areNULL.