1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| WITH tree(No_,comp,[Production BOM No_],level,Qty,qty2,[Version Code])AS (
SELECT a.No_, b.No_ + b.[Version Code] AS comp, b.[Production BOM No_],0,b."Quantity per",b.[Version Code]
FROM table$Item as a JOIN
[table$Production BOM Line] as b ON
a.[Production BOM No_] = b.[Production BOM No_]
WHERE (a.No_= @article)
UNION ALL
SELECT c.No_, d.No_+ d.[Version Code] AS comp, d.[Production BOM No_] ,t.level + 1,d."Quantity per",d.[Version Code]
FROM table$Item as c JOIN
[table$Production BOM Line] as d ON
c.[Production BOM No_] = d.[Production BOM No_]
INNER JOIN tree t ON t.comp=c.No_ )
SELECT @article,tree.* ,0 as zero FROM tree,table$Item where (comp NOT LIKE 'p_%') And [Version Code]='' AND tree.comp =table$Item.No_ ORDER BY tree.level |
Partager