title: Opening Stock, Closing Stock By Date sql Query
body: <p>I have two table with primary key and foreign key (MaterialId)</p>
  
  <ol>
  <li>Material Table (Multiple Material)</li>
  </ol>
  
  <pre>
  MaterialId   MaterialName   OpeningStock
  1            Pen            100
  2            Pencil         50
  </pre>
  
  <ol start="2">
  <li>Material Stock (Multiple Material Entry)</li>
  </ol>
  
  <pre>
  MaterialId   PurchaseQty    SalesQty    Date
  1            500            0           2016-12-15
  1            0              0           2016-12-16
  1            300            0           2016-12-17
  1            0              400         2016-12-18
  1            0              0           2016-12-19
  1            0              0           2016-12-20
  1            0              400         2016-12-21
  1            200            100         2016-12-22
  </pre>
  
  <p>Now When I Pass @FromDate and @Todate
  I want to output like below:</p>
  
  <pre>
  Date         MaterialName   OpeningStock   PurchaseQty   SalesQty    ClosingStock
  2016-12-15   Pen            100            500            0           600
  2016-12-16   Pen            600            0              0           600
  2016-12-17   Pen            600            300            0           900
  2016-12-18   Pen            900            0              400         500
  2016-12-19   Pen            500            0              0           500
  2016-12-20   Pen            500            0              0           500
  2016-12-21   Pen            500            0              400         100
  2016-12-22   Pen            100            200            100         200
  
  </pre>
  
  <p><b>Note : </b><br/>
  1. If Something is wrong on database tables so, please guide me how to handle this situation.
  2. And Also find Current Date Stock From Two Tables</p>