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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Order By with Parameters

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
END

but 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
end

is 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
Go to Top of Page
   

- Advertisement -