saida chary

saida chary

  • NA
  • 24
  • 1.2k

Sql server Order by according to sent params

Aug 17 2017 7:37 AM
I'm sending four id's to the database to get the four questions. and their respected multiple choice options. Everything is fine but when user filtered the questions by 'id', Order by functionality is disturbing. please suggest your code how to get order by through sent parameter.

For Example:

If I'm sending @CaseId VARCHAR(MAX)= '34559|34558|34557|34556'
o/p coming as 34556
34557
34558
34559
If I'm using order by desc the condition fails if the user is not filtered through 'id'. Issue when the user is filtered by 'id'. I want o/p as the sent parameters order not by default order even user filtered or not.

Note: If User selected filter option id's are changing vice versa means asc to desc and desc to asc

Thanks in advance.

Answers (4)