View previous topic :: View next topic |
Author |
Message |
sraj Beginner
Joined: 08 Aug 2006 Posts: 10 Topics: 4
|
Posted: Tue Nov 20, 2007 9:39 pm Post subject: Order by based on input |
|
|
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 |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Wed Nov 21, 2007 2:54 am Post subject: |
|
|
i can't. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Wed Nov 21, 2007 9:16 am Post subject: |
|
|
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 |
|
 |
sraj Beginner
Joined: 08 Aug 2006 Posts: 10 Topics: 4
|
Posted: Wed Nov 21, 2007 1:12 pm Post subject: |
|
|
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 |
|
 |
videlord Beginner
Joined: 09 Dec 2004 Posts: 147 Topics: 19
|
Posted: Fri Nov 23, 2007 3:14 pm Post subject: |
|
|
I'm not sure i'm understand your question
but can you try
select col1, col2, ....
order by 1, 2, ... |
|
Back to top |
|
 |
|
|