[eluser]OverZealous[/eluser] @mrtavo
First, (I'm sure this is a typo in the example only) your example has unbalanced parentheses on the third line.
Ignoring that, what error, specifically, are you getting? What does the generated query look like?
It should work, but without more information I can't really help much. :-(
(Another option, in the short run, is to look at defining a custom SQL function. That's especially useful in more complex cases such as this. Usually done with CREATE FUNCTION on most DB servers.)