Home » SQL & PL/SQL » SQL & PL/SQL » Use of Case in Order by
Use of Case in Order by [message #280714] Wed, 14 November 2007 10:25 Go to next message
bella13
Messages: 90
Registered: July 2005
Member
I want to Order by depending on certain conditions. Is there any way I can order by for different conditions. (No, I do not wish to use dynamic SQL)

I have 2 questions

1. the following is giving me an error if I have more than 1 column in the case, Any idea

ORDER BY
case
when pSortType IS NULL then
report_date,acct_number,description
end desc
)

2. Also the pSortType is a value passed to the procedure. It can be any of 50 columns. How can I include that in my order by clause?


ORDER BY
case
when pSortType = 'Acct Number' then
Acct_Number
when pSortType = 'Acct Name' then
Acct_Name
end desc
)

- Do i have to do the above 50 times, for 50 different fields?

Thanks for your help and time

- Bella
Re: Use of Case in Order by [message #280721 is a reply to message #280714] Wed, 14 November 2007 10:32 Go to previous messageGo to next message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
1. You have to use case three times for three columns.
2. You have to write 50 times. Only other way is to use dynamic sql.

By
Vamsi
Re: Use of Case in Order by [message #280775 is a reply to message #280721] Wed, 14 November 2007 13:22 Go to previous message
bella13
Messages: 90
Registered: July 2005
Member
this worked well. thanks for your help and time
Previous Topic: Exception Handling problem
Next Topic: How to store jpeg file in database
Goto Forum:
  


Current Time: Fri Dec 02 22:44:20 CST 2016

Total time taken to generate the page: 0.14349 seconds