I am working off this example.
http://www.drury.net.nz/2005/04/15/specifying-a-sort-parameter-for-a-tsql-stored-procedure/
CREATE PROCEDURE getEmployees ( @ColumnName varchar(100) )
AS
SELECT
EmployeeID,
FirstName,
LastName,
SSN,
Salary
FROM
Employees
ORDER BY
CASE
WHEN @ColumnName=’LastName’ THEN LastName
WHEN @ColumnName=’Salary’ THEN CONVERT(varchar(50), Salary)
WHEN @ColumnName=’SSN’ THEN SSN
END
The case statement works, but what if I have the following parameters: @SortColumn, @SortDirection.
The @SortColumn could be any column of any type and it seems to use the case statement you have to convert the values to the same type. I suppose I can make them all VARCHAR and just make sure values like DateTime are put in the proper order to sort as I want.
But what if I have the @SortDirection parameter set as ASC or DESC as a VARCHAR value? How can I adjust the query to do change the sort direction?