Subject Using params to choose the order by fields?
Author
Hi All,

I want to give my users the choice of ordering their member list by

FIRST_NAME, SURNAME
or
SURNAME, FIRST_NAME

I managed to get it working using a case statement, but only with one field in Order By clause. If I put in the second field, it gives me an invalid token error on the comma.

How can I get this to work? Thanks for any help.

Or is there a better way to do this?

Cheers,
Paul

SELECT
  MEMBERS.FIRST_NAME,
  MEMBERS.SURNAME,
  MEMBERS.MEMBERID
FROM
  MEMBERS
WHERE
  MEMBERS.CLUBID = :CID
ORDER BY
  CASE :OBC
    WHEN 1 THEN MEMBERS.SURNAME
    WHEN 2 THEN MEMBERS.FIRST_NAME
  END;


The above works, but if I put in 2 fields as below, I get an error.

ORDER BY
  CASE :OBC
    WHEN 1 THEN MEMBERS.SURNAME, MEMBERS.FIRST_NAME
    WHEN 2 THEN MEMBERS.FIRST_NAME, MEMBERS.SURNAME
  END;