I thought you could change the parameter to an int, and sort by the column with that ordinal:
CREATE PROCEDURE [dbo].[CLICK10_GetCP]
@ordinal AS INT
AS
BEGIN
SELECT
acct_nbr,
acct_name
FROM
acct
ORDER BY @Ordinal
END
GO
This throws an nice error (SQL2005):
Msg 1008, Level 16, State 1, Line 4
The SELECT item identified by the
ORDER BY number 1 contains a variable
as part of the expression identifying
a column position. Variables are only
allowed when ordering by an expression
referencing a column name.
Googling around found this solution here (SQL 2005 and up):
CREATE PROCEDURE [dbo].[CLICK10_GetCP]
@switch AS BIT
AS
BEGIN
SELECT
acct_nbr,
acct_name
FROM
acct
ORDER BY CASE
WHEN @switch = 0 THEN (RANK() OVER (ORDER BY acct_nbr, acct_name))
WHEN @switch = 1 THEN (RANK() OVER (ORDER BY acct_name, acct_nbr))
END
GO