Its more readable to use strings wherever possible to represent your sql like
when="$q eq 'all'" or
when="$q eq 'sort_name'".
Mpath expressions also use when condition for evaluating and selecting request elements to be executed.
SQL Query Testing on Resource Save