title: Mysql CASE statement usage with Zend
body: <p>I have the following query that selects some records from the database:</p>
  
  <pre><code>$select_person = $this-&gt;select()
          -&gt;setIntegrityCheck(false)
          -&gt;from(array('a' =&gt; 'tableA'), 
                  array(new Zend_Db_Expr('SQL_CALC_FOUND_ROWS a.id'),
                          'a.cid',  
                          'a.email',
                          'final' =&gt; new Zend_Db_Expr( "concat( '&lt;div 
                              style=\"color:#1569C7; font-weight:bold\"&gt;',
                              a.head , ' ' ,  a.tail,  '&lt;/div&gt;')" ),
                          'a.red_flag'
                  )
          )   
          -&gt;joinLeft(array('b' =&gt; 'tableb'), ... blah blah)
          -&gt;where('blah blah')
          -&gt;order('a.head ASC')
  </code></pre>
  
  <p>I want to modify the above query so that it selects a different value for <code>'final'</code> depending on the value of </p>
  
  <pre><code>a.red_flag.
  </code></pre>
  
  <p>which can have values - true or false.</p>
  
  <p>I understand I can use the CASE statement of mysql - eg something like the following:</p>
  
  <pre><code>'final' =&gt; new Zend_Db_Expr("CASE a.red_flag WHEN 'true' THEN '$concatstr1'
                          ELSE '$concatstr2' END")
  </code></pre>
  
  <p>The value of <code>$concatstr1 = "concat( '&lt;div style=\"color:red; font-weight:bold\"&gt;', a.head , ' ' ,  a.tail,  '&lt;/div&gt;')" ;</code></p>
  
  <p>The value of <code>$concatstr2 = "concat( '&lt;div style=\"color:blue; font-weight:bold\"&gt;', a.head , ' ' ,  a.tail,  '&lt;/div&gt;')" ;</code></p>
  
  <p>However, it throws an error saying </p>
  
  <blockquote>
    <p>Message: SQLSTATE[42000]: Syntax error or access violation: 1064
    You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use
    near 'div 
                          style="color:red; font-weight:bold">',
                              a.head , ' ' , ' at line 1  </p></p>
  </blockquote>
  
  <p>How can I make this query work? 
  Any help is greatly appreciated.</p>
  
  <p>Thanks</p>