Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alternative 'order by' when selecting from db

Status
Not open for further replies.

Fumac

Programmer
Jan 2, 2001
16
0
0
SE
Hello,
I have made a select statement from a database and wonder if there is any possibillity to have two different 'order by'. If the first one doesn´t fit, the second one will be used.
Someting like: order by ($sortBy $order or 1)

Thank you for any answer

/Fumac
 
It´s ok, solved it with an if statement.

Thanks anyway
 
If I truely understand your question, simply use a DECODE statement to differentiate between columns or values to sort on. Just be sure that the options to sort on are of the same type. That is, Column2 and Column3 MUST be of the same datatype. However, Column1 need not be of the same datatype. So here Column1 is a VARCHAR2, but Column2 and Column3 can be numeric.

ORDER BY DECODE(Column1, 'x', Column2, Column3)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top