Skip to content
Advertisement

Dynamic order direction

I writing a SP that accepts as parameters column to sort and direction.

I don’t want to use dynamic SQL.

The problem is with setting the direction parameter.

This is the partial code:

Advertisement

Answer

You could have two near-identical ORDER BY items, one ASC and one DESC, and extend your CASE statement to make one or other of them always equal a single value:

Advertisement