title: Sql sum value subtract by user input in asp.net
body: <p>I am trying to develop Inventory System. I created 3 tables <strong>Product</strong>,<strong>Supplier</strong> and <strong>Purchase</strong>.  </p>
  
  <p><code>Product</code>  </p>
  
  <ul>
  <li>productId(PK)</li>
  <li>productName</li>
  </ul>
  
  <p><code>Supplier</code></p>
  
  <ul>
  <li>SupplierId(Pk)</li>
  <li>CompanyName</li>
  </ul>
  
  <p><code>Purchase</code></p>
  
  <ul>
  <li>PurchaseId(PK)</li>
  <li>ProductId(FK)</li>
  <li>SupplierId(FK)</li>
  </ul>
  
  <p>To show my available stock (Product Name,Company Name and Quantity), I execute a query: </p>
  
  <pre><code>ALTER Proc [dbo].[GroupByTotalStock]
  as
  begin
  select Product.ProductName,Supplier.CompanyName, Sum(Purchase.Quantity) as total
  from Product 
  inner join Purchase on Product.ProductId = Purchase.ProductId
  inner join Supplier on Purchase.SupplierId = Supplier.SupplierId
  group by product.ProductName, Supplier.CompanyName
  end
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/dEIzf.png" alt="Query Result"></p>
  
  <p>I need to add another field <strong>Sales</strong> where i want to display query result data to gridview and search field to search my product information (Product name, company name, Quantity). Then retrieved those data from gridview to text field. </p>
  
  <p><img src="https://i.stack.imgur.com/Cnb58.png" alt="My design screenshot"></p>
  
  <p>Now my questions are:</p>
  
  <ul>
  <li>How can i subtract (which i sell, it is user input) my product total quantity by group wise? </li>
  <li>What would be the query or logic ? </li>
  </ul>
  
  <p>I will also create a table where stored sales information. </p>