It's not as obvious as it sounds, I think. You'll need to use Exec.
Here is some code I posted to show how to query a table based on a param.
You can easily modify it to use ORDER BY dynamically.
CREATE Procedure spTest
(
@tablename nvarchar(25),
@MyID int
)
AS
Declare @mySQLStatement varchar(100)
Select @mySQLStatement = 'SELECT * FROM ' + @tablename + ' WHERE
ID = ' + Cast (@MyID as varchar)
Exec (@mySQLStatement)
HtH
Imar
At 11:04 AM 4/17/2001 -0600, you wrote:
>I feel like a retard asking this, because I'm betting the answer is readily
>apparent...
>
>I would like to order by a variable passed to a sp.. such as:
>
>Create Procedure procIamStupid (@sortOrder varchar(20))
>Select ProductID, Product_Name, Product_Description from Products
>ORDER BY @sortOrder
>RETURN
>
>I can build the SQL statement from within the ASP page, but I'd rather leave
>it up to a SP.
>How can I do this?
>
>Thanks in advance!
>-Arbon Reimer