title: Doctrine 2 Query Builder abs Function
body: <p>This Work:</p>
  <pre><code>    $qb = $this-&gt;em-&gt;createQueryBuilder();
  
      $qb-&gt;select(&quot;abs(u.code) as code&quot;)
         -&gt;from(&quot;User&quot;, &quot;u&quot;)
         -&gt;orderBy(&quot;code&quot;,&quot;ASC&quot;)
         -&gt;getQuery()
         -&gt;getArrayResult();
  </code></pre>
  <p>This Don't Work:</p>
  <pre><code>    $qb = $this-&gt;em-&gt;createQueryBuilder();
  
      $qb-&gt;select(&quot;u.code&quot;)
         -&gt;from(&quot;User&quot;, &quot;u&quot;)
         -&gt;orderBy(&quot;abs(u.code)&quot;,&quot;ASC&quot;)
         -&gt;getQuery()
         -&gt;getArrayResult();
  </code></pre>
  <p>The Error:</p>
  <p><strong>Syntax Error] line 0, col 118: Error: Expected end of string, got '('</strong></p>
  <p>The native doctrine function abs work only on a select part of statment and
  don't work on order by part.</p>
  <p>Obs:</p>
  <blockquote>
  <p>1-) Im avoiding to use NativeQuery.</p>
  <p>2-) u.code is a varchar fild on mysql and need to be varchar ( some times numeric and some times string), and i need to order then like a number in numeric case.</p>
  </blockquote>
  <p>Any Help?</p>