MySQL Forums
Forum List  »  Newbie

Passing DESC and ASC as Variables
Posted by: Jassim Rahma
Date: June 04, 2019 10:07AM

Hi,

I am trying below to pass the DESC and ASC as variables in my stored procedure but it's invalid.

How can I fix this please?


SELECT ads.ad_id, ads.ad_guid, users.display_name, users.user_guid, ads.ad_currency, ads.ad_price, ads.created_date
FROM ads
JOIN users ON users.user_id = ads.created_user
WHERE is_published = TRUE
AND ads.is_blocked = FALSE
AND users.is_blocked = FALSE
ORDER BY
CASE
WHEN @param_sort_by = 'ad_id' THEN ad_id
WHEN @param_sort_by='ad_price' THEN ad_price
WHEN @param_sort_by='display_name' THEN ad_price
END;
CASE
WHEN @param_sort_by = 'DESC' THEN DESC
WHEN @param_sort_by='ASC' THEN ASC
END;


Thanks,
Jassim

Options: ReplyQuote


Subject
Written By
Posted
Passing DESC and ASC as Variables
June 04, 2019 10:07AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.