Applying sort to a query returned by a stored procedure
169891Mar 31 2008 — edited Jul 15 2009I am looking for some advice on the best approach for applying a dynamic sort to a query returned by a stored procedure.
We have a stored procedure that has 3 inputs fields which are used to specify sort columns and it has an additional 3 fields to indicate if the corresponding input column is to be sorted in ascending or descending order. We presently accomplish this by using dynamic SQL in the procedure but this approach has some drawbacks. Ideally we would like these queries to compile just like any other cursor. We have tried using decodes but this does not seem practical or easy to maintain.
This procedure is used by a web application that allows the user to click on a column header to specify their sort preference. The previous sort selection becomes the second sort field and the one before that the third.
Your advice is much appreciated!