Help with complex code

  • Hello. I'd appreciate help with a bit of code that can help me retreive data from one table in my DB.

    The issue here is that on the same table I have a bill of materials that contains the part numbers of the parent part and the child parts. One same part number can have several child parts which in turn can each have more child parts.

    I managed to get the information in an 'indented' form, but I need a 'summarized' form, meaning that instead of having the information horizontally, I need to retreive it vertically, so I can see the whole bill of materials in a simple manner: Parent part first (with quantities), child parts after and 'grandchilds' after that (if any).

    I hope someone can help me out with this.

    Thank you very much in advance.

    Lenar C.

  • lenar.chavez (5/14/2013)


    Hello. I'd appreciate help with a bit of code that can help me retreive data from one table in my DB.

    The issue here is that on the same table I have a bill of materials that contains the part numbers of the parent part and the child parts. One same part number can have several child parts which in turn can each have more child parts.

    I managed to get the information in an 'indented' form, but I need a 'summarized' form, meaning that instead of having the information horizontally, I need to retreive it vertically, so I can see the whole bill of materials in a simple manner: Parent part first (with quantities), child parts after and 'grandchilds' after that (if any).

    I hope someone can help me out with this.

    Thank you very much in advance.

    Lenar C.

    Sounds like you have adjacency list. Take a look at recursive CTEs. If you need more detailed assistance take a few minutes and read the first link in my signature for best practices when posting questions.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply