我进行了递归 cte 查询以获取特定零件编号的材料清单,但我需要的是询问我需要哪个零件编号的 BOM。它工作正常,如果我不能轻松查询不同的零件编号,它就不起作用。
查询如下:
WITH BOM_CTE(COMPONENT, PARENT,QTY,LVL)
AS (SELECT i.fcomponent, i.fparent, i.fqty, 1 AS LVL
FROM dbo.inboms AS i INNER JOIN dbo.invcur ON i.fparent = dbo.invcur.fcpartno
AND i.fparentrev = dbo.invcur.fcpartrev INNER JOIN dbo.inmastx ON dbo.invcur.fcpartno
=dbo.inmastx.fpartno AND dbo.invcur.fcpartrev = dbo.inmastx.frev
WHERE(i.fparent = '124-5130')
UNION ALL
SELECT i.fcomponent, i.fparent, i.fqty, BOM_CTE_1.LVL + 1 AS INC_LVL
FROM dbo.inboms AS i INNER JOIN BOM_CTE AS BOM_CTE_1 ON i.fparent=BOM_CTE_1.COMPONENT)
SELECT B.PARENT, B.COMPONENT, B.QTY, B.LVL
FROM BOM_CTE AS B LEFT OUTER JOIN
BOM_CTE AS C ON B.PARENT = C.COMPONENT
GROUP BY B.PARENT, B.COMPONENT, B.QTY, B.LVL
ORDER BY B.LVL
如您所见,CTE 第一部分中的 WHERE 子句会给我结果,但是这个查询不能在 Excel 中以图形方式表示,因此我不能使用参数来询问零件号。
关于如何实现这一目标的任何想法?