我做了递归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在图形上表示,因此我不能使用参数来请求部件号。
关于如何实现这一目标的任何想法?