title: If value is 0 (zero) then increment it with max number +1
body: <p>I need to UPDATE all new inserted values of 0 with the highest value from the same column + 1. Any value with zero should be updated by the highest value +1.  If the highest value is 30 below in the &quot;Preference&quot; column, then the next value should be 31 for Id 11 and 32 for Id 12.  New values are inserted every 30 seconds, could be multiple, from the source table that I have no access to into the table below (table 1).</p>
  <p>The UPDATE statement is executed when a user drags and drops a row in the web app.</p>
  <pre><code>UPDATE [DB].[dbo].[tbl1] SET
      Preference = @Preference
  WHERE Id = Id
  </code></pre>
  <p>I need to somehow add that logic to this statement described above. This is where I am lost.</p>
  <p>Any ideas?  Thank you for the help!!</p>
  <p>For example:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;">ID</th>
  <th style="text-align: center;">Preference</th>
  <th style="text-align: center;">Account</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">3</td>
  <td style="text-align: center;">7</td>
  <td style="text-align: center;">22</td>
  </tr>
  <tr>
  <td style="text-align: center;">6</td>
  <td style="text-align: center;">8</td>
  <td style="text-align: center;">33</td>
  </tr>
  <tr>
  <td style="text-align: center;">7</td>
  <td style="text-align: center;">9</td>
  <td style="text-align: center;">44</td>
  </tr>
  <tr>
  <td style="text-align: center;">9</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: center;">55</td>
  </tr>
  <tr>
  <td style="text-align: center;">11</td>
  <td style="text-align: center;">0</td>
  <td style="text-align: center;">66</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Required results:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;">ID</th>
  <th style="text-align: center;">Preference</th>
  <th style="text-align: center;">Account</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">3</td>
  <td style="text-align: center;">7</td>
  <td style="text-align: center;">22</td>
  </tr>
  <tr>
  <td style="text-align: center;">6</td>
  <td style="text-align: center;">8</td>
  <td style="text-align: center;">33</td>
  </tr>
  <tr>
  <td style="text-align: center;">7</td>
  <td style="text-align: center;">9</td>
  <td style="text-align: center;">44</td>
  </tr>
  <tr>
  <td style="text-align: center;">9</td>
  <td style="text-align: center;">10</td>
  <td style="text-align: center;">55</td>
  </tr>
  <tr>
  <td style="text-align: center;">11</td>
  <td style="text-align: center;">11</td>
  <td style="text-align: center;">66</td>
  </tr>
  </tbody>
  </table>
  </div>