Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 461259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:57:25+00:00 2026-05-12T22:57:25+00:00

I am developing a Bill Of Materials cost calculator program and I am struggling

  • 0

I am developing a Bill Of Materials cost calculator program and I am struggling to fathom a simple solution to some recursive selects I want.

I am using SQL Server 2005 for this part of the application.

Say I have Product A, which contains assembly B, and Part C. Assembly B will contain parts D and E, but, here is where I struggle, D and or E may contain X number of other assemblies.

I can do something along the lines of;

SELECT * FROM TBLBOM WHERE Parent = A 
UNION 
SELECT * FROM TBLBOM WHERE Parent = B 
UNION 
SELECT * FROM TBLBOM WHERE Parent = C 

To produce something along the lines of;

PARENT    COMP    COST
A          X       £1
B          D       £0.5
B          E       £0.5
....
C          Y       £1

But lets say Component D is made up of Component F & G, how would I accommodate this in a t-sql statement.

In a nutshell, I need to expand out the full component list of all assemblies that are associated to a parent product regardless of whether they are in a sub assembly or a sub assembly of a sub assembly etc…

Ideally I would like to avoid a cursor at all costs 🙂

Any help / guidance would be appreciated.

Thank you.

EDIT;
As requested, here is the table structure and expected output. The parent is the DRAWINGNO and the child node is the PART (which could also be a parent in itself);

BOMID      DRAWINGNO         ITEM            PART               COST     
1303       HGR05180           1              HGR05370           1
1304       HGR05180           2              HGF65050           4
1305       HGR05180           3              HGF50340           1 
1312       HGR05370           1              HPN05075           1 
1313       HGR05370           2              HPN05085           2
1314       HGR05370           3              HPN05080           1
1848       EXP-18G            1              HGR05180           1
1849       EXP-18G            2              HGR05210           3
1850       EXP-18G            3              HGR05230           1
1851       EXP-18G            4              HGR05140           1
1852       EXP-18G            5              HGR05150           2
1853       EXP-18G            6              HGR05050           1
1854       EXP-18G            7              ESC05350           1 
1855       EXP-18G            8              ESC05330           3 
1856       EXP-18G            9              HGR05360           1
1857       EXP-18G            10             HGR05370           2
1858       EXP-18G            11             ESC05640           1  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:57:25+00:00Added an answer on May 12, 2026 at 10:57 pm

    If i understand (and without table structure) you can try something like this

    DECLARE @Table TABLE(
            Component VARCHAR(50),
            Parent VARCHAR(50),
            Cost FLOAT
    )
    
    INSERT INTO @Table SELECT 'B', 'A', 1
    INSERT INTO @Table SELECT 'C', 'B', 2
    INSERT INTO @Table SELECT 'C', 'B', 3
    INSERT INTO @Table SELECT 'D', 'C', 4
    
    DECLARE @Product VARCHAR(50)
    SET @Product = 'A'
    
    ;WITH Selects AS (
            SELECT  *
            FROM    @Table
            WHERE   Parent = @Product
            UNION ALL
            SELECT  t.*
            FROM    @Table t INNER JOIN
                    Selects s ON t.Parent = s.Component
    )
    
    SELECt  *
    FROm    Selects
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Developing a simple game for the iPhone, what gives a better performance? Using a
Well I am developing a simple Tip Calculator app as a part of a
Developing a project of mine I realize I have a need for some level
Developing applications for Android in Eclipse, press F11 to run the program in the
Developing iphone application using makkit framework. I have got the map view integrated in
i developing an application in which i want to bind my own parameter with
Developing an application for Android, i want to record data that will be usefull
I developing a program that draws in elements of the list (QListView). How do
After developing in VS.NET for many years, I'm starting to do some Xcode development
i am developing a project in which i have to print a bill on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.