Now I want to add a parameter('Approved' or 'Declined' or 'Withdrawn') to the stored procedure which is an input from the external user. Based on the user preference I want to sort the output to display.
i.e. if the user selects 'Withdrawn' then the resultant set of the stored procedure must display all the records with 'Withdrawn' status first then the other records.
Currently I am using "Order by status" but unable to understand how to implement the above logic.
Does any one has suggestions or an approach that would be helpful to me?
You can do below in the ORDER BY clause:
ORDER BY NULLIF(Status, @.Your_Parameter)
This will result in NULL if the status matches the passed parameter and status value otherwise. And since NULL values get sorted first in SQL Server those rows will get ordered first.
No comments:
Post a Comment