Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Liza
Starting Member
11 Posts |
Posted - 2006-05-24 : 13:15:09
|
| Hi There,Just trying to do a sp that will allow the user to sort the data based on the parameter entered. I have seen some examples on this site that allow for 1 parameter field in the order by using:ORDER BY CASE WHEN @SortOrder = 1 THEN CompanyName WHEN @SortOrder = 2 THEN ContactName ELSE ContactTitle ENDbut i need to do multiple items as below:order by case @order_by when 'Underwriter' then uw.full_name, received_date desc, a.deal_id when 'Broker House' then br.full_name, received_date desc,a.deal_id else received_date desc, a.deal_id endis there anyway to do this without creating a variable to store all the code and then execute?any help would be greatly appreciated!thanks,Liza |
|
|
Liza
Starting Member
11 Posts |
Posted - 2006-05-24 : 13:48:17
|
| Found the answer on sqlmag.com forum:order by case @order_by when 'Underwriter' then uw.full_name when 'Broker House' then br.full_name end ,received_date desc, a.deal_id |
 |
|
|
|
|
|