title: In MySQL, how do I insert 1 when string value is 'true', 0 when false, while preserving nulls
body: <p>I am using an <code>INSERT</code> query that <code>SELECT</code>s from a plain-text database into a more query-friendly database.  The following is simplified a lot to prevent confusion with unnecessary information, if I've simplified too far for clarity please let me know and I will amend.</p>
  
  <p>Source data appears as follows:</p>
  
  <pre><code>
      |    id (integer)    |    SomeCol (varchar)    |    BooleanCol (varchar)   |    
      ----------------------------------------------------------------------------
      |    1               |    'String Data'        |    'true'                 |
      |    2               |    'Other Data'         |    'false'                |
  </code></pre>
  
  <p>The target table needs to look as follows after my <code>INSERT</code> query:</p>
  
  <pre><code>
      |    id (integer)    |    SomeCol (varchar)    |    BooleanCol (tinyint(1))   |    
      -------------------------------------------------------------------------------
      |    1               |    'String Data'        |    1                         |
      |    2               |    'Other Data'         |    0                         |
  </code></pre>
  
  <p>I'm looking for something that would work more or less like this, borrowing a bit from java syntax:</p>
  
  <pre><code>
      INSERT INTO target(SomeCol, BooleanCol) 
      SELECT SomeCol, (BooleanCol IS NOT NULL ? (BooleanCol == 'true' ? 1 : 0) : null) 
      FROM source
  </code></pre>
  
  <p>Note that the java syntax provided as an example of what I want is intended to preserve <code>null</code>s as needed.</p>
  
  <p>Also, while I'm here, if you happen to know how <code>SELECT</code> the current time stamp from MySQL that would also be helpful.</p>