title: Getting wrong result in SQL Server
body: <p>I have two tables:</p>
  
  <p><strong>Fee_Payable_to_Students</strong>:</p>
  
  <pre><code>f_co |S_Adm_No | apr | may | june | jul | aug | sep | oct | nov | dec | jan | feb | mar
  1    |s_1      |  5  | 5   |  5   | 5   |  5  |  5  | 5   |  5  | 5   |  5  | 5   | 5
  2    |s_1      |  5  | 5   |  5   | 5   |  5  |  5  | 5   |  5  | 5   |  5  | 5   | 5
  </code></pre>
  
  <p><strong>Fee_Assign_Waiver_to_Students</strong>:</p>
  
  <pre><code>f_co|S_Adm_No | apr | may | june | jul | aug | sep | oct | nov | dec | jan | feb | mar
  1   |s_1      |  5  | 5   |  5   | 5   |  5  |  5  | 5   |  5  | 5   |  5  | 5   | 5
  </code></pre>
  
  <p>I want to view my result as </p>
  
  <pre><code>S_Adm_No | Installment                                      | Amount  |Payable_Date
  s_1      |Quarter-1 (April, May &amp;amp; June)                     |  5      |Apr 15, 2018
  s_1      |Quarter-2 (July, August &amp;amp; September)              |  5      |Jul 15, 2018
  s_1      |Quarter-3 (October, November &amp;amp; December)          |  5      |Oct 15, 2018
  s_1      |Quarter-4 (January, February &amp;amp; March)             |  5      |Jan 15, 2019
  </code></pre>
  
  <p>My SQL query is here:</p>
  
  <pre><code>SELECT 
      unPvt.S_Adm_No, Installment, 
      SUM(Amount) AS Amount, 
      CASE 
         WHEN Installment = 'Quarter-1 (April, May &amp;amp; June)' 
            THEN 'Apr 15, 2018'       
         WHEN Installment = 'Quarter-2 (July, August &amp;amp; September)' 
            THEN 'Jul 15, 2018'       
         WHEN Installment = 'Quarter-3 (October, November &amp;amp; December)' 
            THEN 'Oct 15, 2018'       
         WHEN Installment = 'Quarter-4 (January, February &amp;amp; March)' 
            THEN 'Jan 15, 2019' 
      END AS Payable_Date 
  FROM 
      (SELECT 
           pc.S_Adm_No,
           (Apr + May + Jun)-COALESCE(CON.Qa1,0) AS [Quarter-1 (April, May &amp;amp; June)],  
           (Jul + Aug + Sep)-COALESCE(CON.Qa2,0) AS [Quarter-2 (July, August &amp;amp; September)],   
           (Oct + Nov + Dec)-COALESCE(CON.Qa3,0) AS [Quarter-3 (October, November &amp;amp; December)],   
           (Jan + Feb + Mar)-COALESCE(CON.Qa4,0) AS [Quarter-4 (January, February &amp;amp; March)]   
       FROM 
           Fee_Payable_to_Students pc
       LEFT JOIN
           (SELECT 
                S_Adm_no,
                SUM(E_Apr + E_May + E_Jun) Qa1, 
                SUM(E_Jul + E_Aug + E_Sep) Qa2,
                SUM(E_Oct + E_Nov + E_Dec) Qa3, 
                SUM(E_Jan + E_Feb + E_Mar) Qa4
            FROM 
                Fee_Assign_Waiver_to_Students w
            GROUP BY 
                S_Adm_No) AS CON ON pc.S_Adm_no = CON.S_Adm_no
        WHERE
            pc.S_Adm_No = s_1) AS Pvt 
  UNPIVOT 
      (Amount FOR Installment IN 
                                  ([Quarter-1 (April, May &amp;amp; June)], 
                                  [Quarter-2 (July, August &amp;amp; September)], 
                                  [Quarter-3 (October, November &amp;amp; December)], 
                                  [Quarter-4 (January, February &amp;amp; March)])) AS unPvt 
      GROUP BY unPvt.S_Adm_No,unPvt.Installment
  </code></pre>