asked on
;WITH LaborAndOverheadCosts (Assembly_Item_Key, Labor_Cost, Overhead_Cost, Assembly_Location) AS
(
SELECT
Assembly_Item_Key,
Labor_Cost,
Overhead_Cost, Assembly_Location
FROM BM_View_SL_BOMS
),
MakeQuantities (Make_Buy, Quantity, Item_Location, Assembly_Item_Key, Item_Key) AS
(
SELECT Make_Buy, Quantity, Item_Location, BM_View_SL_BOMItems.Assembly_Item_Key, Item_Key
FROM BM_View_SL_BOMItems
--LEFT OUTER JOIN BM_View_SL_BOMS ON
--BM_View_SL_BOMItems.Item_Key = BM_View_SL_BOMS.Assembly_Item_Key
where Make_Buy = 'Make'
and BM_View_SL_BOMItems.Assembly_Item_Key IN (select Assembly_Item_Key from BM_View_SL_BOMS)
and BM_View_SL_BOMItems.Assembly_Item_Key IN ('70-1010-BRX0014', '1001311', '1001258')
),
Hierarchy (Item, Labor_Cost, Overhead_Cost, Make_Buy, Item_Location, Quantity, Assembly_Item_Key) AS
(
SELECT LaborAndOverheadCosts.Assembly_Item_Key as Item, LaborAndOverheadCosts.Labor_Cost,
LaborAndOverheadCosts.Overhead_Cost, MakeQuantities.Make_Buy,
MakeQuantities.Item_Location, MakeQuantities.Quantity, MakeQuantities.Assembly_Item_Key
FROM LaborAndOverheadCosts
LEFT OUTER JOIN MakeQuantities ON
LaborAndOverheadCosts.Assembly_Item_Key = MakeQuantities.Item_Key
where LaborAndOverheadCosts.Assembly_Item_Key IN ('70-1010-BRX0014', '1001311', '1001258')
)
SELECT Item, Labor_Cost, Overhead_Cost, Make_Buy, Item_Location, Quantity, Assembly_Item_Key
FROM Hierarchy
+-----------------+------------+---------------+----------+---------------+----------+-------------------+
| Item | Labor_Cost | Overhead_Cost | Make_Buy | Item_Location | Quantity | Assembly_Item_Key |
+-----------------+------------+---------------+----------+---------------+----------+-------------------+
| 1001258 | 0.00058 | 0.00082 | Make | BZMFG | 667.63 | 1001311 |
| 1001311 | 4.59195 | 6.42873 | Make | BZMFG | 1 | 70-1010-BRX0014 |
| 70-1010-BRX0014 | 0.4125 | 0.5775 | NULL | NULL | NULL | NULL |
+-----------------+------------+---------------+----------+---------------+----------+-------------------+