Home Forums SQL Server 2012 SQL Server 2012 - T-SQL How to get up to 5 hierarchy levels of data from original (parent) to derived (children) product table. RE: How to get up to 5 hierarchy levels of data from original (parent) to derived (children) product table.

  • I came from a mfg background, and dealt with multi level BOM's.
    A parent would be listed as level 1, children level 2.
    Level 2 children could themselves be a parent, with a level 3 list of components.
    From your description, you mention 6 levels, although ours varied and went deeper.
    We were going from a mfg parent, and then blowing through to all the purchased components and qtys that it took to build any parent item.
    I think what you are looking for is a CTE to make a distinct list of parents, and then chase down the hierarchy.
    And then create more of an indented BOM look for the results.
    Parent A
      Child A
      Child B
         Child 1 of B
        Child 2 of B
    Your lists of results seem a bit confusing to me, as Parents are being repeated in what should be all the Child Items only.
    So you may want to add a better example of what you really want to see in the end.
    Especially where in my example, Child B is a Parent in it's own right, but also consumed as a sub assembly when Parent A is made.
    Your requirements likely differ from ours, as we also could have a sub assembly qty of more than 1 per parent, so a bit of math might be in order.

    Hope this helps.