title: Split total sum into categories based on range
body: <p>I am trying to split my total count of sales into categories using MSSQL.</p>
  
  <p>So for example the total sales for October was 557.361. I would need to split that sum into three categories, calculating the bonus price based on each category, while the remainder overflows into the next category.</p>
  
  <p>Is this possible using MSSQL?</p>
  
  <p>See the below sample:</p>
  
  <pre><code>IF OBJECT_ID('tempdb..#sales') IS NOT NULL
      DROP TABLE #sales;
  
  CREATE TABLE #sales
  (
      year_month VARCHAR(10),
      total_sales INT
  );
  
  
  INSERT INTO #sales
  (
      year_month,
      total_sales
  )
  VALUES
  ('2019-10-01', 557361),
  ('2019-11-01', 621801);
  </code></pre>
  
  <p>This would be the desired results, see the image below.</p>
  
  <p><a href="https://i.stack.imgur.com/Kb6Hu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kb6Hu.png" alt="enter image description here"></a></p>