Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • 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
Sheriff
Posts: 35976
422
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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!