Skip to content
Advertisement

Conditional Order By in sql server with multiple order columns

i wish to perform conditional order by with multiple columns i am expecting a query like

can we achieve this.?

sample data

result i need is

Advertisement

Answer

I think this is what you want:

Appreciate that when price is NULL, the above reduces to:

That is, the alternate CASE expressions just collapse to NULL, leaving the above equivalent to:

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