title: MassUpdate with calculation and rounding
body: <p>I have a table column that I want to do a calculating with 2 table fields and a bind parameter.</p>
  
  <pre><code>id | transaction_id | local_price | supplier_price | discrepancy
  </code></pre>
  
  <p>I want to calculate</p>
  
  <blockquote>
    <p>discrepancy = (supplier_price - local_price) / $count</p>
  </blockquote>
  
  <p>(and <code>supplier_price</code> and <code>local_price</code> values are in the table. The <strong><code>discrepancy</code> should be in INT</strong>.</p>
  
  <p>So I wrote this php function</p>
  
  <pre><code>$cases = [];
  $ids = [];
  $params = [];
  $discrepancyParam = [];
  
  foreach ($array as $key =&gt; $value) {
       $transactionId = $value['transaction_id'];
       $cases[] = "WHEN {$transactionId} then ?";
       $ids[] = $transactionId;
       $params[] = "ceil((supplier_price-local_price)/" . $value['count'] . ")";
   }
  
  $ids = implode(',', $ids);
  $cases = implode(' ', $cases);
  
  \DB::update("UPDATE accounting SET `discrepancy` = CASE `transaction_id` {$cases} END WHERE `transaction_id` in ({$ids})", $params);
  </code></pre>
  
  <p>This generates </p>
  
  <blockquote>
    <p>UPDATE accounting SET <code>discrepancy</code> = CASE <code>transaction_id</code> WHEN 37801 then ceil((supplier_price-local_price)/27) WHEN 37874 then ceil((supplier_price-local_price)/21) ... END WHERE <code>transaction_id</code> in (37801,37874,...)</p>
  </blockquote>
  
  <p>But I get an error:</p>
  
  <blockquote>
    <p>General error: 1366 Incorrect integer value: 'ceil((supplier_price-local_price)/27)' for column 'discrepancy' at row 14195</p>
  </blockquote>
  
  <p>I think I am doing wrong with my query but I couldn't figure out what. </p>
  
  <p><strong>Update</strong></p>
  
  <p>I took only 1 element from each array and it showed this query:</p>
  
  <blockquote>
    <p>General error: 1366 Incorrect integer value: 'ceil(<code>ups_price</code>-<code>local_price</code>)' for column 'discrepancy' at row 14195 (SQL: UPDATE accounting SET <code>discrepancy</code> = CASE <code>transaction_id</code> WHEN 37801 then ceil(<code>supplier_price</code>-<code>local_price</code>) END WHERE <code>transaction_id</code> in (37801))</p>
  </blockquote>
  
  <p>So I took it and run in MySQLWorkbench</p>
  
  <pre><code>UPDATE accounting SET `discrepancy` = CASE `transaction_id` WHEN 37801 then ceil(`supplier_price`-`local_price`) END WHERE `transaction_id` in (37801)
  </code></pre>
  
  <p>Putting this in MySQLWorkbench works however in my code it doesn't. </p>
  
  <p>I suspect it should be something related with my way of calling the DB fields in php</p>
  
  <hr>
  
  <p><strong>Update 2</strong>:</p>
  
  <p>Even this doesn't work although <code>supplier_price</code> is INT for surely. It's definitely calling table field in php</p>
  
  <pre><code>These throw same error:
  $params[] = "supplier_price";
  $params[] = "`supplier_price`";
  </code></pre>