hystericalmarks
MIS
Is it at all possible to use a variable in an Order By clause? I need a stored procedure that would select records in a table and order them by different columns depending on the @Orderby parameter passed. Obviously, the following syntax does not work:<br><br>Create Procedure sp_Test<br>@Orderby varchar(30)<br>As<br>Select *<br>From Test<br>Order by @Orderby<br><br>The only other option I've considered is using 'If' statements for each possible Order by. Anyone else have any ideas?<br>Thanks for you help.<br><br>