title: Stored procedure and print output
body: <p>Based on my previous question, I'm trying to print various columns from different tables and only print the top 10 most profitable products and it is calculated by sellingprice - costprice. How can I print out the top 10 output line by line like its on a table?</p>
  
  <pre><code>CREATE PROCEDURE usp_top10ProfitableProducts
       @productID int Output,
       @productdes VARCHAR(100) Output,
       @quantityorder int Output,
       @totalProfit DECIMAL(5,2) Output
  AS
  BEGIN
      SELECT Top 10 * 
      FROM
          (SELECT 
               @productID = productID, 
               @productdes = Product.description, 
               @quantityorder = CustomerInventory.quantityOrdered, @totalProfit = (Inventory.sellingPrice-Inventory.costPrice) AS difference
           FROM 
               Product p, Supplier s, SupplierOrder so, Inventory in, CustomerInventory cin
           WHERE 
               p.ProductID = s.productID, s.supplierID = so.supplierID, so.supOrderID = in.supOrderID, in.barcodeNo = cin.barcodeNo) difference_data
      ORDER BY 
         difference DESC
  
      DECLARE @productID INT
      DECLARE @productdes VARCHAR(100)
      DECLARE @quantityorder INT
      DECLARE @totalProfit DECIMAL(5,2)
  
      EXECUTE usp_top10ProfitableProducts
          @productID OUT
          @productdes OUT
          @quantityORDER OUT
          @totalProfit OUT
  
      PRINT
  </code></pre>