It's too late in the afternoon to translate this into German

Have you maybe read this article? SQL: Made to Order.

This is the Article published in the July 2009 edition iSeries Nation Network newsletter. The original article can be found in the Tekkie-Corner (Chapter 3) at http://www.sss-software.de/inn/power...-PowerInfo.pdf
The above link does not work anymore, but you can still access it here SQL: Made to Order. (with some extra info as well**).

IMO, using too many "case when" statements makes the statement hard to maintain for the next developer (as you have found). In your example I would definitely use traditional dynamic SQL (at the cost of a slight performance hit) and build the statement into a string.

**For example, you can put your sort sequences into a file and simply fetch the sequence needed. This means should you have a new sequence option, you add it to the file and don't need to even change the program anymore.

Hope this helps.