title: How to manipulate SQL Data
body: <p>I have set of query like below but the result are not like i want</p>
  
  <pre><code>SELECT * INTO #Temp FROM (SELECT Product,PeriodNum,OpenBal,Month Qty,0 as OnHandQty
                        FROM   StockTransaction
                        WHERE Company = 1 AND 
                              FiscalYear = 2016 AND
                              DeptCode = 'phst' and
                              Product = 'Product A' and
                              PeriodNum between 1 and 10) A 
  
  SELECT * INTO #Temp2 FROM (SELECT Product,PeriodNum,OpenBal,Month Qty,OnHandQty
                        FROM   StockTransaction
                        WHERE Company = 1 AND 
                              FiscalYear = 2016 AND
                              DeptCode = 'phst' and
                              Product = 'Product A' and
                              PeriodNum between 1 and 10 and
                              PeriodNum = (SELECT max(PeriodNum) 
                                           from StockTransaction s 
                                           WHERE s.DeptCode =  StockTransaction.DeptCode and 
                                                  s.ItemCode = StockTransaction.ItemCode)) C 
  
  SELECT * INTO #Temp3 FROM (C.Product,C.PeriodNum,C.OpenBal,C.Month Qty,C.OnHandQty                               
                         FROM #Temp2 C INNER JOIN 
                              #Temp T ON C.DeptCode = T.DeptCode and 
                                         C.ItemCode = T.ItemCode and 
                                         C.PeriodNum = T.PeriodNum) as  E
  
  SELECT * INTO #Result FROM (SELECT * FROM #Temp
                          UNION ALL SELECT * FROM  #Temp3)  As result
  
  SELECT * FROM #Result
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/FMgrf.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/FMgrf.jpg" alt="enter image description here"></a></p>
  
  <p>can you help me how to manipulate the data i get???i only data display like picture. If got 5 row of data from select statment, the <strong>OpenBal</strong> value only display for minimum <strong>PeriodNum</strong> and the <strong>OnHandQty</strong> value only display for maximum of <strong>PeriodNum</strong></p>