Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 dynamic ORDER BY combining different sort order
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ask SQLTeam Question

0 Posts

Posted - 02/12/2001 :  09:11:20  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
Elisabeth writes "I want to create a stored proc similar to the examples shown in your article 'dynamic ORDER BY'.
But it's not possible to include a different sort order (ASC/DESC) in the ORDER BY case.

-- sample code--

CREATE PROCEDURE ps_Customers_SELECT_DynamicOrderBy
@SortOrder tinyint = NULL
SELECT CompanyName,
FROM Customers
ORDER BY CASE WHEN @SortOrder = 1 THEN CompanyName ASC
WHEN @SortOrder = 2 THEN CompanyName DESC
ELSE ContactTitle

Do you know have an idea how to solve this problem ?

Thank you"

Chief SQLTeam Crack Dealer

4149 Posts

Posted - 02/12/2001 :  09:11:20  Show Profile  Visit graz's Homepage  Reply with Quote
Please read the FAQ ( I think the third item will answer your question.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000