Over the years I've gotten into the habit (not entirely sure if good or bad, part of the reason for the question) of using if conditionals for formatting, or group functions, and date functions for date formatting.
Examples:
// Grouping: get total goals & assists for each player (1 = goal, 2,3 = assist)
SUM(IF(scoreType=1,1,0)) AS goals, SUM(IF(scoreType=2,1,IF(scoreType=3,1,0))) AS assists
// Date formatting:
DATE_FORMAT(gameDate, '%b %e') AS displayDate
// Text formatting:
IF(gameType='S','(S)','') AS gameTypeDisplay
I would be fine continuing on as is, but I'm moving to an ORM based system where "select *" is the default, and field substitution (to achieve the above), while possible, just makes an utter mess of things when you have multiple conditions to handle in your query (basically better to have pure, readable SQL, or ORM DSL, but not a mish mash of the two, imo).
So, what are the costs involved in moving say, the text formatting conditional above to middleware layer? e.g. 1,000 row query result; loop, and apply conditional for each row?
Basically I'd like to clean up middleware/ORM layer code and offload convenience SQL functions, but only if I'm not going to drag the server to a slow grind as middleware layer performs tons of extra processing.
Server setup is 32-bit CentOS 5, JVM (Groovy middleware) with MySQL 5 latest.