Skip to content
Advertisement

Find max value from coalesce function

This is my query:

My expected output is:

I tried to use coalesce like :

I know coalesce returns first not null value. So what I can do to get my desired result.

Advertisement

Answer

coalesce() has nothing to do with this. Unfortunately, SQL Server does not support greatest(). But you can use apply:

The max() ignores NULL values, so this does what you expect.

Here is a db<>fiddle.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement