Conditional order by clause with multiple columns
I would like to know whether it is possible to include multiple columns in a conditional order by clause.
Ex: I have written the following PL / SQL :
CREATE PROCEDURE GetProducts
(
@OrderBy VARCHAR(50),
@Input2 VARCHAR(30)
)
AS
BEGIN
SET NOCOUNT ON
SELECT Id, ProductName, Description, Price, Quantity
FROM Products
WHERE ProductName LIKE @Input2
ORDER BY
CASE
WHEN @OrderBy = 'ProductNameAsc' THEN ProductName
END ASC,
CASE
WHEN @OrderBy = 'ProductNameDesc' THEN ProductName
END DESC
END
Now I want to include when the Orderby - "Productnameasc" then order by productname, price, stdate
else
orderby productname, crdate, category
Could this be done? I tried it, but couldn't get this to work.
Any help is greatly appreciated.