MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Order by based on input

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
sraj
Beginner


Joined: 08 Aug 2006
Posts: 10
Topics: 4

PostPosted: Tue Nov 20, 2007 9:39 pm    Post subject: Order by based on input Reply with quote

Select col1, col2, col3
from table 1
order by col1 <ASC/DESC>, col2 <ASC/DESC>, col3 <ASC/DESC>

The sort order for col1, col2, col3 are parameters to the program. Can anyone explain how to parametrize the sort order without using a dynamic sql.
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Wed Nov 21, 2007 2:54 am    Post subject: Reply with quote

i can't.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Wed Nov 21, 2007 9:16 am    Post subject: Reply with quote

Why would you want to complicate the SQL and/or the program to avoid dynamic SQL? Try it. You'll like it. 8)
Back to top
View user's profile Send private message
sraj
Beginner


Joined: 08 Aug 2006
Posts: 10
Topics: 4

PostPosted: Wed Nov 21, 2007 1:12 pm    Post subject: Reply with quote

kolusu wrote:
sraj,

If you do not want to deal with dynamic SQL then define 3 cursors each with a different order by clause and open the cursor based on the parameter. At any given point of time you will open only one cursor.

Kolusu
_________________


If I don't parametrize, I need more than 3 SQLS(3! SQLs(6 SQLs)). I might need more SQLs if there are 4 columns in order by(4!SQLS(24 SQLs). I'm trying to use CASE statement, not sure whether it works for this scenario.
Back to top
View user's profile Send private message
videlord
Beginner


Joined: 09 Dec 2004
Posts: 147
Topics: 19

PostPosted: Fri Nov 23, 2007 3:14 pm    Post subject: Reply with quote

I'm not sure i'm understand your question
but can you try
select col1, col2, ....
order by 1, 2, ...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group