I have a stored procedure that will accept 2 different parameters. The first parameter will determine which column I want to sort on, the second parameter will determine whether it is ASC
or DESC
Create Procedure Some_SP
@sortcolumn varchar(10)
@sortorder varchar(10)
AS
Select * from empTable
Order by
CASE @sortcolumn WHEN 'First_Name' THEN fname END,
CASE @sortcolumn WHEN 'Last_Name' THEN lname END,
CASE @sortcolumn WHEN 'ID' THEN empID END,
CASE @sortorder WHEN 'ascending' THEN ASC END,
CASE @sortorder WHEN 'descending' THEN DESC END
It is giving me syntax error. How do I fix it so that I can have 2 conditions in my CASE statement?