Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help with Query – Nested List from Parent Child

Author  Topic 

JBelthoff
Posting Yak Master

173 Posts

Posted - 2012-06-27 : 13:43:19
I have a table representing a very large assembled product with numerous subassemblies. The table is a Parent/Child hierarchy and nests down 10 levels deep. I need to get a list of Parts marked as [Rep] = 1 for each next parent up the hierarchy that is marked with [CanOverhaul] = 1 like this:

ID ARID PartNo QTY
4 60 60-PartNo 4
4 61 61-PartNo 4
4 62 62-PartNo 4
4 70 70-PartNo 1
79 90 90-PartNo 1
79 92 92-PartNo 6
79 109 109-PartNo 1
79 149 149-PartNo 1
79 150 150-PartNo 1
79 151 151-PartNo 1
79 152 152-PartNo 1
79 232 232-PartNo 1
79 233 233-PartNo 2
79 234 234-PartNo 1
79 1440 1440-PartNo 48
79 1454 1454-PartNo 2
79 1463 1463-PartNo 24
etc...


I have a DDL you can use to set up the sample data located here: [url]http://www.datalissol.com/sql/Auto%20Replacement%20Parts.txt[/url]

It is kind of large.... Sorry...

Any help would be appreciated.

Thanks,

JBelthoff
› As far as myself... I do this for fun!

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2012-06-27 : 17:39:54
Sorry but I'm not following the rules.
can you post just a small amount of data (rather than the full 11K rows) and the actual desired output based on that small sample?
Be sure to include cases where the middle of the hierarchy contains canoverhaul=0 and/or rep=0 so we can see if that breaks the linage or if we just filter those out but still work up/down the hierarchy. And what is the logical starting place to start working up (or down) the hierarchy? Is it all rows where sublevel = 10 or just for any given part...
Can I assume that ID and PID is the childid and parentid respectively? And what is ARID (posted above)? That is not in your table.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -