Using variables for asc and desc in order by [duplicate]

without Dynamic SQL each option it’s clause for example:

ORDER BY
  case when @var1 = 'priority asc' THEN priority END ASC ,
  case when @var1 = 'priority desc' then priority end DESC,
  case when @var2 = 'report_date asc' then report_date end ASC,
  case when @var2 = 'report_date desc' then report_date end DESC

Leave a Comment