I just asked a question linked here about Summing from a CASE/WHEN query. Part of my question was answered, which leads to another question.
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.
Items 00011 and 00011S are made up from item ST1FJP91 which has a NULL overhead cost.
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.
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:
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
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