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
 Other Forums
 Other Topics
 Using VARIABLES with Order By

Author  Topic 

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2000-08-13 : 00:00:00
Gregory writes "I'm learning ASP and have virtually no experiene with SQL and would like to know the following...

Can I sort by variables in SQL??
{Ex: SELECT * FROM Products ORDER BY }

My goal is to be able take a table, say 5 columns wide, and be able to allow the user to specify which column (i.e. ) they want to sort by, and then which order of sorting (i.e. ) they want.

Using variables in my SQL string will allow me to avoid using a wickedly long IF THEN ELSE set-up in ASP!

Any easy solutions?"

The easiest way to do this is to create the SQL statement dynamically in ASP before you get to SQL Server. Please see this article on dynamic SQL inside SQL Server.
   

- Advertisement -