dynamic sorting | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

dynamic sorting

Hi, does anyone know if it is possible to pass the sorting order to a report thru parameters?
I have a form where a user can specify how he would like the report to be sorted (company name asc, zip code desc, city desc, etc). The form’s submit event generates the parameters that are passed to the report.
I tried to set the sorting order of my table thru an expression (= Parameters!order_by.Value) but this does not work.. thanks in advance for your help.
You need a CASE for each possible sort combination. ORDER BY
CASE WHEN @sort = ‘ASC’ and @part = ‘engine’ THEN v.engine END ASC
CASE WHEN @sort = ‘DESC’ and @part = ‘engine’ THEN v.engine END DESC
MeanOldDBA
[email protected] When life gives you a lemon, fire the DBA.
]]>