where site = #{site} and part_no = #{partNo} and eng_chg_level = #{engChgLevel} and bom_type = #{bomType} and alternative_no = #{alternativeNo} and by_prod_line_item_no = #{byProdLineItemNo} and component_line_item_no = #{componentLineItemNo}
where site = #{site} and part_no = #{partNo} and eng_chg_level = #{engChgLevel} and bom_type = #{bomType} and alternative_no = #{alternativeNo} and by_prod_line_item_no = #{byProdLineItemNo} and component_line_item_no = #{componentLineItemNo}
</update>
</update>
<!--查bom子明细-->
<!--多层级 BOM 展开:IFS CONNECT BY 语义;子装配解析在 DefaultChildBom(非递归)中完成。递归成员仅 INNER JOIN,避免 SQL Server 对递归 CTE 的限制(禁止派生表/子查询/外连接/OPTION)。-->
ORDER BY bh.eff_phase_in_date DESC, bh.create_date DESC
) AS rn
FROM plm_bom_detail bd
INNER JOIN plm_bom_header bh ON bd.site = bh.site AND bd.part_no = bh.part_no
AND bd.bom_type = bh.bom_type AND bd.eng_chg_level = bh.eng_chg_level
INNER JOIN part_revision pr ON pr.site = bh.site AND pr.part_no = bh.part_no AND pr.eng_chg_level = bh.eng_chg_level
WHERE bd.alternative_no = '*'
AND pr.eff_phase_out_date IS NULL
AND ISNULL(bd.status, '') <![CDATA[<>]]> 'Obsolete'
) pick
WHERE pick.rn = 1
),
ExplodedBom AS (
SELECT
1 AS structure_level,
CAST(RIGHT(REPLICATE('0', 8) + CAST(a.line_sequence AS VARCHAR(8)), 8) AS VARCHAR(8000)) AS sort_key,
a.site,
a.part_no,
dbo.get_part_name(a.site, a.part_no) AS partDesc,
a.bom_type,
a.eng_chg_level,
a.alternative_no,
b.alternative_description,
a.component_part,
dbo.get_part_name(a.site, a.component_part) AS componentPartDesc,
a.qty_per_assembly,
a.print_unit,
dbo.get_um_name(a.print_unit) AS printUnitName,
c.product_group_id4,
dbo.get_product_group_name(c.site, c.product_group_id4, '4') AS productGroupName4,
c.min_order_qty,
c.mul_order_qty,
c.planning_method,
c.cum_lead_time,
c.unprotected_lead_time,
dbo.get_cum_lead_time(a.site, a.component_part) AS componentCumLeadTime,
dbo.get_unprotected_lead_time(a.site, a.component_part) AS componentUnprotectedLeadTime
FROM plm_bom_component AS a
LEFT JOIN plm_bom_detail AS b ON a.site = b.site AND a.part_no = b.part_no AND a.bom_type = b.bom_type
AND a.eng_chg_level = b.eng_chg_level AND a.alternative_no = b.alternative_no
LEFT JOIN part AS c ON a.site = c.site AND a.part_no = c.part_no
WHERE a.site = #{site}
AND a.part_no = #{partNo}
AND a.bom_type = #{bomType}
AND a.eng_chg_level = #{engChgLevel}
AND a.alternative_no = #{alternativeNo}
AND a.qty_per_assembly >= 0
UNION ALL
SELECT
p.structure_level + 1,
CAST(p.sort_key + '.' + RIGHT(REPLICATE('0', 8) + CAST(a.line_sequence AS VARCHAR(8)), 8) AS VARCHAR(8000)),
a.site,
a.part_no,
dbo.get_part_name(a.site, a.part_no) AS partDesc,
a.bom_type,
a.eng_chg_level,
a.alternative_no,
b.alternative_description,
a.component_part,
dbo.get_part_name(a.site, a.component_part) AS componentPartDesc,
a.qty_per_assembly,
a.print_unit,
dbo.get_um_name(a.print_unit) AS printUnitName,
c.product_group_id4,
dbo.get_product_group_name(c.site, c.product_group_id4, '4') AS productGroupName4,
c.min_order_qty,
c.mul_order_qty,
c.planning_method,
c.cum_lead_time,
c.unprotected_lead_time,
dbo.get_cum_lead_time(a.site, a.component_part) AS componentCumLeadTime,
dbo.get_unprotected_lead_time(a.site, a.component_part) AS componentUnprotectedLeadTime
FROM ExplodedBom AS p
INNER JOIN DefaultChildBom AS cb ON cb.site = p.site AND cb.part_no = p.component_part AND cb.bom_type = p.bom_type
INNER JOIN plm_bom_component AS a ON a.site = cb.site AND a.part_no = cb.part_no
AND a.bom_type = cb.bom_type AND a.eng_chg_level = cb.eng_chg_level AND a.alternative_no = cb.alternative_no
INNER JOIN plm_bom_detail AS b ON a.site = b.site AND a.part_no = b.part_no AND a.bom_type = b.bom_type
AND a.eng_chg_level = b.eng_chg_level AND a.alternative_no = b.alternative_no
INNER JOIN part AS c ON a.site = c.site AND a.part_no = c.part_no
WHERE p.structure_level < 100
AND a.qty_per_assembly >= 0
)
SELECT
SELECT
a.site,
a.part_no,
dbo.get_part_name(a.site, a.part_no) as partDesc,
a.bom_type,
a.eng_chg_level,
a.alternative_no,
b.alternative_description,
a.component_part,
dbo.get_part_name(a.site, a.component_part) as componentPartDesc,
a.qty_per_assembly,
a.print_unit,
dbo.get_um_name(a.print_unit) as printUnitName,
c.product_group_id4,
dbo.get_product_group_name(c.site, c.product_group_id4, '4') as productGroupName4,
c.min_order_qty,
c.mul_order_qty,
c.planning_method,
c.cum_lead_time,
c.unprotected_lead_time,
dbo.get_cum_lead_time(a.site, a.component_part) as componentCumLeadTime,
dbo.get_unprotected_lead_time(a.site, a.component_part) as componentUnprotectedLeadTime
FROM plm_bom_component as a
LEFT JOIN plm_bom_detail as b on a.site = b.site and a.part_no = b.part_no and a.bom_type = b.bom_type and a.eng_chg_level = b.eng_chg_level and a.alternative_no = b.alternative_no
LEFT JOIN part as c on a.site = c.site and a.part_no = c.part_no
where a.site = #{site} and a.part_no = #{partNo} and a.bom_type = #{bomType} and a.eng_chg_level = #{engChgLevel} and a.alternative_no = #{alternativeNo}