title: SQL - SUMMING CASE/WHEN Continued
body: <p>I just asked a question linked <a href="https://stackoverflow.com/questions/37865838/sql-summing-case-when-values-from-different-fields/37866376#37866376">here</a> about Summing from a CASE/WHEN query. Part of my question was answered, which leads to another question.</p>
  
  <p>See picture below:<br>
    <a href="https://i.stack.imgur.com/i45FE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i45FE.png" alt="enter image description here"></a></p>
  
  <p>I have three fields, item_no, comp_item_no and Overhead. The comp_item_no is a list of component items for the item_no field. This means that items 00011PP, 00011PPX and 00011X, are at least partially created from item 00011.  </p>
  
  <p>Items 00011 and 00011S are made up from item ST1FJP91 which has a NULL overhead cost.  </p>
  
  <p>Unfortunately, the Overhead value displayed in the field does not take component items into consideration. Instead of the $23.44 displayed for item_no 00011PP, the true Overhead value would be $23.44 + $16.02, or $39.46. That is because item_no 00011 was at least partially used in creating item_no 00011PP and it's Overhead value needs to reflect that.</p>
  
  <p>I need to find a way to SUM these overhead values to  include their respective component items, but I cannot find a feasible solution. Here is my query showing the rest of the story: </p>
  
  <pre><code>SELECT 'Overhead' = Sum(CASE
                        WHEN vac_type IN ( 'A01', 'AD0', 'ADX', 'AO1',
                                                        'CI0', 'DO1', 'DP9', 'O20',
                                                        'PWO', 'TO1', 'WO1', 'WO2' ) 
  THEN ( Cost_values)
                        ELSE NULL
                      END),
     item_no,
     comp_item_no
  FROM   Table_1       
  GROUP BY item_no,
           comp_item_no 
  </code></pre>
  
  <p>Just so you know, vac_type is an identifier for different Values, meaning when vac_type IN ( 'A01', 'AD0', 'ADX', 'AO1', 'CI0', 'DO1', 'DP9', 'O20',PWO', 'TO1', 'WO1', 'WO2' ), then the Values are Overhead</p>