• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic ORDER BY in Stored Procs

 
Mike Fourier
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies: This is not really a JDBC question. But I thought someone here might know.

In Sybase, I'm trying to do dynamic ORDER BY clause in my stored procedure, and the trick is, I also want to dynamically determine direction (ASC, DESC).

Using Google, I've come up with this, but I'm wondering if anyone knows a way to do this, without having to duplicate significant portions of code:

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34669
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,
This is the right forum for general SQL questions and stored procedures unless we have another forum dedicated to it.

My Sybase is from a number of years ago, but I vaguely remember being able to store the SQL statement in a stored proc variable and run it using "exec". This would let you just concat the one piece that is different without duplicating the bulk of the query.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic