Ken McNamee has been thinking outside the SQL box. I didn't realize that you can use a "case" statement in the "order by" clause:
DECLARE @orderBy varchar(50)SET @orderBy = 'LastName'SELECT *FROM EmployeesORDER BY CASE WHEN @orderBy = 'LastName' THEN LastName END, CASE WHEN @orderBy = 'HireDate' THEN HireDate END
For more on this, see his post: http://blogs.vertigosoftware.com/kenm/archive/2005/12/06/Dynamic_ORDER_BY_Clause.aspx
Remember Me
Page rendered at Tuesday, February 07, 2012 2:36:31 PM (Central Standard Time, UTC-06:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.