title: SQL Server query problem. example is in excel sheet picture
body: <p>Please see the following pic and i want to convert this formula in SQL Server.
  in excel sheet</p>
  <pre><code>        M   N
      15  1   0
      16  3   1
      17  5   2
      18  8   4
      19  9   4
  
  
      N= IF(M16-M15&lt;=1,N15,M16-M15-1+N15
  </code></pre>
  <p>Please see the screenshot for reference:</p>
  <p><a href="https://i.stack.imgur.com/R2KOl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R2KOl.jpg" alt="Excel formula for calculation required in SQL Server" /></a></p>