I wrote this query...the variables are just examples:
Can one modify the query, to sort the results by the order of the input variables?Code:SELECT* FROM View_ChammVerPri
WHEREcharindex(VerID,'00101001,00201001,00101002')>0
Printable View
I wrote this query...the variables are just examples:
Can one modify the query, to sort the results by the order of the input variables?Code:SELECT* FROM View_ChammVerPri
WHEREcharindex(VerID,'00101001,00201001,00101002')>0
To do that I think you'd need to use separate Select statements for each input, and Union them together.
To do the sorting, add an extra value in the Select list (eg: "SELECT *, 1 as Sort_Order FROM"), then sort by that value.
If this was a stored procedure I would fill a temporary table or table variable with the input selection - along with an "order column" for sorting. Then join to this table.
What is your backend DB?
You might be able to actually order by that CHARINDEX value as well - have you tried that?
ORDER BY charindex(VerID,'00101001,00201001,00101002')