title: Using window function quantity until total consumed
body: <p>I've been researching CTE with window functions trying to determine if it's possible to update inventory quantity records with an order quantity until the order quantity is consumed without recursive method because of window functions introduced in sql server
  i have found best solutions
  here <a href="https://stackoverflow.com/questions/7843129/cte-recursively-update-quantity-until-total-consumed">CTE - recursively update quantity until total consumed</a></p>
  
  <p>But it is very complex to understand for beginners like me..Please any one convert to Cte with window function will very helpfull..
  i have tried window function to calculate Running quantity..But not succeded.. i am using Sql sevrer 2012..Pls  help me to convert the solutions in window function without recursive</p>
  
  <p>Sample data:</p>
  
  <pre><code>CREATE TABLE [dbo].[myOrder](
    [Account] [float] NOT NULL,
    [Item] [float] NOT NULL,
    [Quantity] [float] NOT NULL
  ) ON [PRIMARY]
  
  insert into dbo.myOrder values (12345, 1, 50)
  
  CREATE TABLE [dbo].[myInventory](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [Account] [float] NOT NULL,
    [InvDate] [numeric](18, 0) NOT NULL,
    [Item] [float] NOT NULL,
    [Quantity] [float] NOT NULL,
    [QuantitySold] [float] NOT NULL
  ) ON [PRIMARY]
  
  insert into dbo.myInventory values (12345, 111287, 1, 45, 40)
  insert into dbo.myInventory values (12345, 111290, 1, 40, 0)
  insert into dbo.myInventory values (12345, 111290, 1, 12, 0)
  insert into dbo.myInventory values (12345, 111291, 1, 25, 0)
  
  
  Expected Result:
  
  ID  Account Item    QuantitySoldNew
  1   12345   1         5
  2   12345   1        40
  3   12345   1         5
  </code></pre>