Can I do "ORDER BY" by passing parameter if there's more than 1 column in parameter?
For example, the parameter is 'number asc,name' , how i can use the passed parameter to order by?
You can use CASE..WHEN.. here
Sample:
SELECT * FROM @table
ORDER BY (CASE @SortItem WHEN 'number asc' THEN number END) asc,
(CASE @SortItem WHEN 'name desc' THEN name END) desc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With